Many of the programmers were stucks in file scanning for virus ,me also stucked in that about 2 weeks.
Actually it's not in the code we stuck...The installation of antivirus and running the service in the pc were we stuck and the lack of proper documentation of installation and running the service.
ClamAv is the only antivirus engine available as an open source till now...
On this post, i will help you guys to install clamAv in windows and use clamAv service for scanning files for virus using java
1) Download ClamAv from https://www.clamav.net/downloads
download proper .msi file for your windows version. current version for windows 64 bit (clamav-0.99.2-x64.msi)Double click and install clamAv.
2) Download ClamAv virus database from the same page
or download main.cvd from the direct link http://database.clamav.net/main.cvd
and daily.cvd from the direct link http://database.clamav.net/daily.cvd
put these two files where you install clamAv (default location will be c drive--> program files--> clamAv)
3) They will provide sample files for clamd.conf and freshclam.conf
studying these files and creating config file will be the next challenge for you..So i will give you the config files just put these file in the clamAv root directory(where clamAv is installed)
a) clamd.conf ( https://drive.google.com/file/d/0B1n0939T4he7Z2xnME0tZFdMazg/view?usp=sharing )
b) freshclam.conf ( https://drive.google.com/file/d/0B1n0939T4he7c3YtWEZ2a3FaOWM/view?usp=sharing )
Edit the clamd.config file
DatabaseDirectory-->path of virus database files(main.cvd and daily.cvd)
TCPAddr-->your currenct ip address
4) Now run cmd as administrator
Change cmd to clamAv directory
then run command--> clamd.exe install
That's it!!!!!!!!!This will start service of clamAv in your system
5) Now scan the file using java
Download these third party jars
a) org.apache.commons.logging-1.1.1.jar
b) commons-io-2.0.jar
c) libclamav-1.0.jar ( https://drive.google.com/file/d/0B1n0939T4he7d1JyYnE2RlB1OGc/view?usp=sharing )
import java.io.FileInputStream;
import java.io.InputStream;
import net.taldius.clamav.ClamAVScanner;
import net.taldius.clamav.ClamAVScannerFactory;
/**
* Class to scan files using ClamAV antivirus APIs.
*
* @author Aneesh T.G
*
*/
public class ClamAVFileScan {
private ClamAVScanner scanner;
public static void main(String args[]){
boolean scanResult=false;
ClamAVFileScan clamAVFileScan=new ClamAVFileScan();
try {
clamAVFileScan.initScanner();
scanResult=clamAVFileScan.fileScanner("C:\\Users\\Aneesh.T.G\\Desktop\\eicar.zip");
if(scanResult){
System.out.println("No virus found");
}
else{
System.out.println("Warning!!!! Virus found");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Method to initialize clamAV scanner
*/
public void initScanner(){
ClamAVScannerFactory.setClamdHost("192.168.0.7"); // Host ip where 'clamd' process is running
ClamAVScannerFactory.setClamdPort(3310); // Port on which 'clamd' process is listening
ClamAVScannerFactory.setConnectionTimeout(20);// Connection time out to connect 'clamd' process
this.scanner = ClamAVScannerFactory.getScanner();
}
/**
* Method to scans files to check whether file is virus infected
*
* @param fileInputStream
* @return
* @throws Exception
*/
public boolean fileScanner(String fileInputStream) throws Exception {
boolean resScan = false;
if (fileInputStream != null) {
InputStream file=new FileInputStream(fileInputStream);
resScan = scanner.performScan(file);
} else {
throw new Exception();
}
return resScan;
}
}
6) Create a test virus file or download eicar.zip and check...Happy coding!!!! :)
Actually it's not in the code we stuck...The installation of antivirus and running the service in the pc were we stuck and the lack of proper documentation of installation and running the service.
ClamAv is the only antivirus engine available as an open source till now...
On this post, i will help you guys to install clamAv in windows and use clamAv service for scanning files for virus using java
1) Download ClamAv from https://www.clamav.net/downloads
download proper .msi file for your windows version. current version for windows 64 bit (clamav-0.99.2-x64.msi)Double click and install clamAv.
2) Download ClamAv virus database from the same page
or download main.cvd from the direct link http://database.clamav.net/main.cvd
and daily.cvd from the direct link http://database.clamav.net/daily.cvd
put these two files where you install clamAv (default location will be c drive--> program files--> clamAv)
3) They will provide sample files for clamd.conf and freshclam.conf
studying these files and creating config file will be the next challenge for you..So i will give you the config files just put these file in the clamAv root directory(where clamAv is installed)
a) clamd.conf ( https://drive.google.com/file/d/0B1n0939T4he7Z2xnME0tZFdMazg/view?usp=sharing )
b) freshclam.conf ( https://drive.google.com/file/d/0B1n0939T4he7c3YtWEZ2a3FaOWM/view?usp=sharing )
Edit the clamd.config file
DatabaseDirectory-->path of virus database files(main.cvd and daily.cvd)
TCPAddr-->your currenct ip address
4) Now run cmd as administrator
Change cmd to clamAv directory
then run command--> clamd.exe install
That's it!!!!!!!!!This will start service of clamAv in your system
5) Now scan the file using java
Download these third party jars
a) org.apache.commons.logging-1.1.1.jar
b) commons-io-2.0.jar
c) libclamav-1.0.jar ( https://drive.google.com/file/d/0B1n0939T4he7d1JyYnE2RlB1OGc/view?usp=sharing )
1)
ClamAVFileScan.java import java.io.FileInputStream;
import java.io.InputStream;
import net.taldius.clamav.ClamAVScanner;
import net.taldius.clamav.ClamAVScannerFactory;
/**
* Class to scan files using ClamAV antivirus APIs.
*
* @author Aneesh T.G
*
*/
public class ClamAVFileScan {
private ClamAVScanner scanner;
public static void main(String args[]){
boolean scanResult=false;
ClamAVFileScan clamAVFileScan=new ClamAVFileScan();
try {
clamAVFileScan.initScanner();
scanResult=clamAVFileScan.fileScanner("C:\\Users\\Aneesh.T.G\\Desktop\\eicar.zip");
if(scanResult){
System.out.println("No virus found");
}
else{
System.out.println("Warning!!!! Virus found");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Method to initialize clamAV scanner
*/
public void initScanner(){
ClamAVScannerFactory.setClamdHost("192.168.0.7"); // Host ip where 'clamd' process is running
ClamAVScannerFactory.setClamdPort(3310); // Port on which 'clamd' process is listening
ClamAVScannerFactory.setConnectionTimeout(20);// Connection time out to connect 'clamd' process
this.scanner = ClamAVScannerFactory.getScanner();
}
/**
* Method to scans files to check whether file is virus infected
*
* @param fileInputStream
* @return
* @throws Exception
*/
public boolean fileScanner(String fileInputStream) throws Exception {
boolean resScan = false;
if (fileInputStream != null) {
InputStream file=new FileInputStream(fileInputStream);
resScan = scanner.performScan(file);
} else {
throw new Exception();
}
return resScan;
}
}
6) Create a test virus file or download eicar.zip and check...Happy coding!!!! :)