source: gs2-extensions/malware-checker/trunk/java/src/main/java/org/greenstone/virustotal/GetFileScanReport.java@ 33664

Last change on this file since 33664 was 33664, checked in by davidb, 4 years ago

Initial version code for running VirusTotal API against files, CLI scripts

File size: 2.8 KB
Line 
1package org.greenstone.virustotal;
2import com.kanishka.virustotal.dto.FileScanReport;
3import com.kanishka.virustotal.dto.VirusScanInfo;
4import com.kanishka.virustotal.exception.APIKeyNotFoundException;
5import com.kanishka.virustotal.exception.UnauthorizedAccessException;
6import com.kanishka.virustotalv2.VirusTotalConfig;
7import com.kanishka.virustotalv2.VirustotalPublicV2;
8import com.kanishka.virustotalv2.VirustotalPublicV2Impl;
9
10import java.io.*;
11import java.util.*;
12import java.lang.*;
13import java.io.UnsupportedEncodingException;
14import java.util.HashMap;
15import java.util.Map;
16
17
18public class GetFileScanReport {
19
20
21 public static void main(String[] args) {
22 try {
23 VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey("09311639ef4193fc22faa35d493a5bf12dc44844a55f03812e40bd1a16fd7b6f");
24 VirustotalPublicV2 virusTotalRef = new VirustotalPublicV2Impl();
25
26 String resourceID = null;
27 resourceID = args[0];
28 FileScanReport report = virusTotalRef.getScanReport(resourceID);
29
30 System.out.println("MD5 :\t" + report.getMd5());
31 System.out.println("Perma link :\t" + report.getPermalink());
32 System.out.println("Resource :\t" + report.getResource());
33 System.out.println("Scan Date :\t" + report.getScanDate());
34 System.out.println("Scan Id :\t" + report.getScanId());
35 System.out.println("SHA1 :\t" + report.getSha1());
36 System.out.println("SHA256 :\t" + report.getSha256());
37 System.out.println("Verbose Msg :\t" + report.getVerboseMessage());
38 System.out.println("Response Code :\t" + report.getResponseCode());
39 System.out.println("Positives :\t" + report.getPositives());
40 System.out.println("Total :\t" + report.getTotal());
41
42 Map<String, VirusScanInfo> scans = report.getScans();
43 for (String key : scans.keySet()) {
44 VirusScanInfo virusInfo = scans.get(key);
45 System.out.println("Scanner : " + key);
46 System.out.println("\t\t Resut : " + virusInfo.getResult());
47 System.out.println("\t\t Update : " + virusInfo.getUpdate());
48 System.out.println("\t\t Version :" + virusInfo.getVersion());
49 }
50
51 } catch (APIKeyNotFoundException ex) {
52 System.err.println("API Key not found! " + ex.getMessage());
53 System.exit(1);
54 } catch (UnsupportedEncodingException ex) {
55 System.err.println("Unsupported Encoding Format!" + ex.getMessage());
56 System.exit(2);
57 } catch (UnauthorizedAccessException ex) {
58 System.err.println("Invalid API Key " + ex.getMessage());
59 System.exit(3);
60 } catch (Exception ex) {
61 System.err.println("Something Bad Happened! " + ex.getMessage());
62 System.exit(4);
63 }
64 }
65}
Note: See TracBrowser for help on using the repository browser.