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

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

Changed code so api key can be in separate file, and passed in on the command-line to the Java code

File size: 3.0 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 public static void printUsage() {
21 System.err.println("Usage: GetFileScanReport api-key resource-id");
22 System.exit(1);
23 }
24
25 public static void main(String[] args) {
26 try {
27 String apiKey = null;
28 String resourceID = null;
29
30 if (args.length==2) {
31 apiKey = args[0];
32 resourceID = args[1];
33 }
34 else {
35 printUsage();
36 }
37
38 VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey(apiKey);
39 VirustotalPublicV2 virusTotalRef = new VirustotalPublicV2Impl();
40
41 FileScanReport report = virusTotalRef.getScanReport(resourceID);
42
43 System.out.println("MD5 :\t" + report.getMd5());
44 System.out.println("Perma link :\t" + report.getPermalink());
45 System.out.println("Resource :\t" + report.getResource());
46 System.out.println("Scan Date :\t" + report.getScanDate());
47 System.out.println("Scan Id :\t" + report.getScanId());
48 System.out.println("SHA1 :\t" + report.getSha1());
49 System.out.println("SHA256 :\t" + report.getSha256());
50 System.out.println("Verbose Msg :\t" + report.getVerboseMessage());
51 System.out.println("Response Code :\t" + report.getResponseCode());
52 System.out.println("Positives :\t" + report.getPositives());
53 System.out.println("Total :\t" + report.getTotal());
54
55 Map<String, VirusScanInfo> scans = report.getScans();
56 for (String key : scans.keySet()) {
57 VirusScanInfo virusInfo = scans.get(key);
58 System.out.println("Scanner : " + key);
59 System.out.println("\t\t Resut : " + virusInfo.getResult());
60 System.out.println("\t\t Update : " + virusInfo.getUpdate());
61 System.out.println("\t\t Version :" + virusInfo.getVersion());
62 }
63
64 } catch (APIKeyNotFoundException ex) {
65 System.err.println("API Key not found! " + ex.getMessage());
66 System.exit(1);
67 } catch (UnsupportedEncodingException ex) {
68 System.err.println("Unsupported Encoding Format!" + ex.getMessage());
69 System.exit(2);
70 } catch (UnauthorizedAccessException ex) {
71 System.err.println("Invalid API Key " + ex.getMessage());
72 System.exit(3);
73 } catch (Exception ex) {
74 System.err.println("Something Bad Happened! " + ex.getMessage());
75 System.exit(4);
76 }
77 }
78}
Note: See TracBrowser for help on using the repository browser.