VirusTotal is a web service that performs url/file scan with some virus scanners. It provides some very simple public API, so that we can automate the file submission and report checking process. There was not a Java class to do this task, so that I decided to code it.
I'm working on the possibility to upload a file and scan it. I let you updated...
>> You can find the whole code here [JVirusTotal]. You can look at the following example for further information.
JVirusTotal vt = new JVirusTotal(your_API_key);
String url = "http://www.x.x";
// submit an URL
vt.submitScanURL(url);
// retrieve an URL scan report
vt.retrieveURLscan(url);
// retrieve a file scan report
vt.retrieveFilescan(getMD5Sum(new URL(url)));
The following class is used to get the MD5 hash of a file, by giving its URL.
import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; import java.net.MalformedURLException; import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class md5 { /** * it calculates the md5sum * * @param url file url * @return md5sum */ public static String getMD5Sum(URL url) { MessageDigest digest = null; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } byte[] buffer = new byte[8192]; int read = 0; String output = ""; InputStream is = null; try { is = url.openStream(); while( (read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); output = bigInt.toString(16); } catch(IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch(IOException e) { e.printStackTrace(); } } return output; } public static void main (String[] s) throws MalformedURLException{ System.out.println(getMD5Sum(new URL("http://www.x.x"))); } }
nice useful attempt :)
Good ;)
Great doc! it will be very helpful for more & more java's VirusTotal extensions. thx~
can u send the java code used to upload the file to virus total
@sheryl
I'm quite busy during this period.. I'll upload it as finished! :)
I let you tuned.
how much time approximately will it take for u to send it.iam in an urgent need of it.thanx for ur reply
great doc
Great APi!!