1 | package org.greenstone.virustotal;
|
---|
2 | import com.kanishka.virustotal.dto.FileScanReport;
|
---|
3 | import com.kanishka.virustotal.dto.VirusScanInfo;
|
---|
4 | import com.kanishka.virustotal.exception.APIKeyNotFoundException;
|
---|
5 | import com.kanishka.virustotal.exception.UnauthorizedAccessException;
|
---|
6 | import com.kanishka.virustotalv2.VirusTotalConfig;
|
---|
7 | import com.kanishka.virustotalv2.VirustotalPublicV2;
|
---|
8 | import com.kanishka.virustotalv2.VirustotalPublicV2Impl;
|
---|
9 |
|
---|
10 | import java.io.*;
|
---|
11 | import java.util.*;
|
---|
12 | import java.lang.*;
|
---|
13 | import java.io.UnsupportedEncodingException;
|
---|
14 | import java.util.HashMap;
|
---|
15 | import java.util.Map;
|
---|
16 |
|
---|
17 |
|
---|
18 | public 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 | }
|
---|