1 | package org.greenstone.virustotal;
|
---|
2 | import com.kanishka.virustotal.dto.ScanInfo;
|
---|
3 | import com.kanishka.virustotal.exception.APIKeyNotFoundException;
|
---|
4 | import com.kanishka.virustotal.exception.UnauthorizedAccessException;
|
---|
5 | import com.kanishka.virustotalv2.VirusTotalConfig;
|
---|
6 | import com.kanishka.virustotalv2.VirustotalPublicV2;
|
---|
7 | import com.kanishka.virustotalv2.VirustotalPublicV2Impl;
|
---|
8 | import java.io.*;
|
---|
9 | import java.util.*;
|
---|
10 | import java.lang.*;
|
---|
11 | import java.io.UnsupportedEncodingException;
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 | public class ScanFile {
|
---|
16 | public static void printUsage(){
|
---|
17 | System.err.println("Usage: ScanFile [-all] api-key file");
|
---|
18 | System.exit(1);
|
---|
19 | }
|
---|
20 |
|
---|
21 | public static void main(String[] args) {
|
---|
22 | String apiKey = null;
|
---|
23 | String inputFileName = null;
|
---|
24 |
|
---|
25 | boolean printall=false;
|
---|
26 | if (args.length<1 || args.length>3){
|
---|
27 | printUsage();
|
---|
28 |
|
---|
29 | }
|
---|
30 | else if(args.length==3){
|
---|
31 | if(args[0].equals("-all")){
|
---|
32 | apiKey = args[1];
|
---|
33 | inputFileName = args[2];
|
---|
34 | printall=true;
|
---|
35 | }
|
---|
36 | else{
|
---|
37 | printUsage();
|
---|
38 | }
|
---|
39 |
|
---|
40 | }
|
---|
41 | else if(args.length==2){
|
---|
42 | apiKey = args[0];
|
---|
43 | inputFileName = args[1];
|
---|
44 | }
|
---|
45 | else {
|
---|
46 | printUsage();
|
---|
47 | }
|
---|
48 |
|
---|
49 | try {
|
---|
50 |
|
---|
51 | VirusTotalConfig.getConfigInstance().setVirusTotalAPIKey(apiKey);
|
---|
52 |
|
---|
53 | VirustotalPublicV2 virusTotalRef = new VirustotalPublicV2Impl();
|
---|
54 |
|
---|
55 | ScanInfo scanInformation = virusTotalRef.scanFile(new File(inputFileName));
|
---|
56 | int responseCode = scanInformation.getResponseCode();
|
---|
57 | if(responseCode!=1){
|
---|
58 | System.err.println("Error:Failed to preform scan.");
|
---|
59 | System.out.println("Verbose Msg :\t" + scanInformation.getVerboseMessage());
|
---|
60 | System.exit(6);
|
---|
61 | }
|
---|
62 | if (printall){
|
---|
63 | System.out.println("___SCAN INFORMATION___");
|
---|
64 | System.out.println("MD5 :\t" + scanInformation.getMd5());
|
---|
65 | System.out.println("Perma Link :\t" + scanInformation.getPermalink());
|
---|
66 | System.out.println("Resource :\t" + scanInformation.getResource());
|
---|
67 | System.out.println("Scan Date :\t" + scanInformation.getScanDate());
|
---|
68 | System.out.println("Scan Id :\t" + scanInformation.getScanId());
|
---|
69 | System.out.println("SHA1 :\t" + scanInformation.getSha1());
|
---|
70 | System.out.println("SHA256 :\t" + scanInformation.getSha256());
|
---|
71 | System.out.println("Verbose Msg :\t" + scanInformation.getVerboseMessage());
|
---|
72 | System.out.println("Response Code :\t" + scanInformation.getResponseCode());
|
---|
73 | System.out.println("done.");
|
---|
74 |
|
---|
75 | }
|
---|
76 |
|
---|
77 | else {
|
---|
78 | System.out.println(scanInformation.getResource());
|
---|
79 | }
|
---|
80 |
|
---|
81 | } catch (APIKeyNotFoundException ex) {
|
---|
82 | System.err.println("API Key not found! " + ex.getMessage());
|
---|
83 | System.exit(2);
|
---|
84 | } catch (UnsupportedEncodingException ex) {
|
---|
85 | System.err.println("Unsupported Encoding Format!" + ex.getMessage());
|
---|
86 | System.exit(3);
|
---|
87 | } catch (UnauthorizedAccessException ex) {
|
---|
88 | System.err.println("Invalid API Key " + ex.getMessage());
|
---|
89 | System.exit(4);
|
---|
90 | } catch (Exception ex) {
|
---|
91 | System.err.println("Something Bad Happened! " + ex.getMessage());
|
---|
92 | System.exit(5);
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|