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