Examples

This page contains examples of all the features available as part of this implementation. Use this page for reference for use of this API.

How to use API

These are the different types of API usees:

Sending and scanning files

Example 1: with java.io.File

            
package me.vighnesh.api.virustotal.examples;

import java.io.File;
import java.io.IOException;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.FileScanMetaData;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class FileScanner {

    public static void main(String[] args) throws IOException {
        File file = new File("FILE YOU WANT TO SCAN");
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        FileScanMetaData scanFile = virusTotal.scanFile(file);
        System.out.println("---SCAN META DATA---");
        System.out.println("");
        System.out.println("MD5 : " + scanFile.getMD5());
        System.out.println("SH-1 : " + scanFile.getSHA1());
        System.out.println("SHA-256 : " + scanFile.getSHA256());
        System.out.println("Permalink : " + scanFile.getPermalink());
        System.out.println("Resource : " + scanFile.getResource());
        System.out.println("Scan Id : " + scanFile.getScanId());
        System.out.println("Response Code : " + scanFile.getResponseCode());
        System.out.println("Verbose Message : " + scanFile.getVerboseMessage());
    }
}
                    
                 
        

Example 2: with java.io.FileInputStream

        
package me.vighnesh.api.virustotal.examples;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.FileScanMetaData;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class FileScannerWithFileInputStream {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        FileInputStream fileInputStream = new FileInputStream("FILE YOU WANT TO SCAN");
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        FileScanMetaData scanFile = virusTotal.scanFile("File Name", fileInputStream);
        System.out.println("---SCAN META DATA---");
        System.out.println("");
        System.out.println("MD5 : " + scanFile.getMD5());
        System.out.println("SH-1 : " + scanFile.getSHA1());
        System.out.println("SHA-256 : " + scanFile.getSHA256());
        System.out.println("Permalink : " + scanFile.getPermalink());
        System.out.println("Resource : " + scanFile.getResource());
        System.out.println("Scan Id : " + scanFile.getScanId());
        System.out.println("Response Code : " + scanFile.getResponseCode());
        System.out.println("Verbose Message : " + scanFile.getVerboseMessage());
    }
}

        
        

Rescanning already submitted files

Example 1:

          
package me.vighnesh.api.virustotal.examples;

import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.FileScanMetaData;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class FileReScanner {

    public static void main(String[] args) {
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        FileScanMetaData reScanFile = virusTotal.reScanFile("FILE MD5 or SHA-1, SHA-256, SCAN-ID");
        System.out.println("MD5 : " + reScanFile.getMD5());
        System.out.println("SH-1 : " + reScanFile.getSHA1());
        System.out.println("SHA-256 : " + reScanFile.getSHA256());
        System.out.println("Permalink : " + reScanFile.getPermalink());
        System.out.println("Resource : " + reScanFile.getResource());
        System.out.println("Scan Id : " + reScanFile.getScanId());
        System.out.println("Response Code : " + reScanFile.getResponseCode());
        System.out.println("Verbose Message : " + reScanFile.getVerboseMessage());
    }
}

          
          

Example 2:

        

package me.vighnesh.api.virustotal.examples;

import java.util.List;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.FileScanMetaData;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class FilesReScanner {

    public static void main(String[] args) {
        String fileId1 = "FILE MD5 or SHA-1, SHA-256, SCAN-ID";
        String fileId2 = "FILE MD% or SHA-1, SHA-256, SCAN-ID";
        String[] fileIds = new String[]{fileId1, fileId2};
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        List reScanFiles = virusTotal.reScanFiles(fileIds);
        reScanFiles.stream().map((reScanFile) -> {
            System.out.println("MD5 : " + reScanFile.getMD5());
            return reScanFile;
        }).map((reScanFile) -> {
            System.out.println("SH-1 : " + reScanFile.getSHA1());
            return reScanFile;
        }).map((reScanFile) -> {
            System.out.println("SHA-256 : " + reScanFile.getSHA256());
            return reScanFile;
        }).map((reScanFile) -> {
            System.out.println("Permalink : " + reScanFile.getPermalink());
            return reScanFile;
        }).map((reScanFile) -> {
            System.out.println("Resource : " + reScanFile.getResource());
            return reScanFile;
        }).map((reScanFile) -> {
            System.out.println("Scan Id : " + reScanFile.getScanId());
            return reScanFile;
        }).map((reScanFile) -> {
            System.out.println("Response Code : " + reScanFile.getResponseCode());
            return reScanFile;
        }).map((reScanFile) -> {
            System.out.println("Verbose Message : " + reScanFile.getVerboseMessage());
            return reScanFile;
        }).forEach((_item) -> {
            System.out.println("");
        });
    }
}

        
        

Retrieving file scan reports

Example 1:

        
package me.vighnesh.api.virustotal.examples;

import java.util.Map;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.FileScan;
import me.vighnesh.api.virustotal.dao.FileScanReport;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class FileReporter {

    public static void main(String[] args) {
        String fileId = "FILE MD5 or SHA-1, SHA-256, SCAN-ID";
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        FileScanReport fileReport = virusTotal.getFileReport(fileId);
        Map scans = fileReport.getScans();
        scans.keySet().stream().forEach((scan) -> {
            FileScan report = scans.get(scan);
            System.out.println("Scan Engine : " + scan);
            if (report.isDetected()) {
                System.out.println("Version : " + report.getVersion());
                System.out.println("Update : " + report.getUpdate());
                System.out.println("Malware : " + report.getMalware());
            } else {
                System.out.println("No Virus Detected");
            }
        });
    }
}

        
        

Example 2:

        
package me.vighnesh.api.virustotal.examples;

import java.util.List;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.FileScan;
import me.vighnesh.api.virustotal.dao.FileScanReport;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class FilesReporter {

    public static void main(String[] args) {
        String fileId1 = "FILE MD5 or SHA-1, SHA-256, SCAN-ID";
        String fileId2 = "FILE MD5 or SHA-1, SHA-256, SCAN-ID";
        String[] fileIds = new String[]{fileId1, fileId2};
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        List filesReports = virusTotal.getFilesReport(fileIds);
        System.out.println("---SCAN REPORTS---");
        System.out.println("");
        filesReports.stream().map((fileReport) -> fileReport.getScans()).map((scans) -> {
            scans.keySet().stream().forEach((scan) -> {
                FileScan report = scans.get(scan);
                System.out.println("Scan Engine : " + scan);
                if (report.isDetected()) {
                    System.out.println("Version : " + report.getVersion());
                    System.out.println("Update : " + report.getUpdate());
                    System.out.println("Malware : " + report.getMalware());
                } else {
                    System.out.println("No Virus Detected");
                }
            });
            return scans;
        }).forEach((_item) -> {
            System.out.println("");
        });
    }
}

        
        

Sending and scanning URLs

Example 1:

        
package me.vighnesh.api.virustotal.examples;

import java.io.IOException;
import java.net.URL;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.URLScanMetaData;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class URLScanner {

    public static void main(String[] args) throws IOException {
        String url = "http://vighnesh.me";
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        URLScanMetaData scanURL = virusTotal.scanURL(new URL(url));
        System.out.println("---SCAN META DATA---");
        System.out.println("");
        System.out.println("URL : " + scanURL.getUrl());
        System.out.println("Resource : " + scanURL.getResource());
        System.out.println("Scan Date : " + scanURL.getScanDate());
        System.out.println("Scan Id : " + scanURL.getScanId());
        System.out.println("Response Code : " + scanURL.getResponseCode());
        System.out.println("Permalink : " + scanURL.getPermalink());
        System.out.println("VerboseMessage : " + scanURL.getVerboseMsg());
    }
}

        
        

Example 2:

        
package me.vighnesh.api.virustotal.examples;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.URLScanMetaData;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class URLsScanner {

    public static void main(String[] args) throws MalformedURLException {
        URL url1 = new URL("http://vighnesh.me");
        URL url2 = new URL("http://vighneswarrao.com");

        URL[] urls = new URL[]{url1, url2};

        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        List scanURLs = virusTotal.scanURLs(urls);
        System.out.println("---SCAN  META DATA---");
        System.out.println("");
        scanURLs.stream().map((scanURL) -> {
            System.out.println("URL : " + scanURL.getUrl());
            return scanURL;
        }).map((scanURL) -> {
            System.out.println("Resource : " + scanURL.getResource());
            return scanURL;
        }).map((scanURL) -> {
            System.out.println("Scan Date : " + scanURL.getScanDate());
            return scanURL;
        }).map((scanURL) -> {
            System.out.println("Scan Id : " + scanURL.getScanId());
            return scanURL;
        }).map((scanURL) -> {
            System.out.println("Response Code : " + scanURL.getResponseCode());
            return scanURL;
        }).map((scanURL) -> {
            System.out.println("Permalink : " + scanURL.getPermalink());
            return scanURL;
        }).map((scanURL) -> {
            System.out.println("VerboseMessage : " + scanURL.getVerboseMsg());
            return scanURL;
        }).forEach((_item) -> {
            System.out.println("");
        });
    }
}

        
        

Retrieving URL scan reports

Example 1:

        
package me.vighnesh.api.virustotal.examples;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.URLScan;
import me.vighnesh.api.virustotal.dao.URLScanReport;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class URLReporter {

    public static void main(String[] args) throws MalformedURLException {
        URL url = new URL("http://eicar.org");
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        URLScanReport urlReport = virusTotal.getURLReport(url);
        System.out.println("---SCAN META DATA---");
        System.out.println("");
        System.out.println("Response Code : " + urlReport.getResponseCode());
        System.out.println("Resource : " + urlReport.getResource());
        System.out.println("Scan ID : " + urlReport.getScanId());
        System.out.println("Permalink : " + urlReport.getPermalink());
        System.out.println("Scan Date : " + urlReport.getScanDate());
        System.out.println("Positives : " + urlReport.getPositives());
        System.out.println("Total : " + urlReport.getTotal());
        System.out.println("File Scan Id : " + urlReport.getFilescanId());

        Map scans = urlReport.getScans();
        System.out.println("---URL REPORT---");
        System.out.println("");
        scans.keySet().stream().forEach((String scan) -> {
            URLScan report = scans.get(scan);
            System.out.println(scan + "\t:" + report.getReport());
        });
    }
}

        
        

Example 2:

        
package me.vighnesh.api.virustotal.examples;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.URLScan;
import me.vighnesh.api.virustotal.dao.URLScanReport;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class URLsReporter {

    public static void main(String[] args) throws MalformedURLException {
        URL url1 = new URL("http://vighnesh.me");
        URL url2 = new URL("http://vighneswarrao.com");

        URL[] urls = new URL[]{url1, url2};

        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        List urlReports = virusTotal.getURLsReport(urls);
        System.out.println("---URLS REPORT---");
        System.out.println("");
        urlReports.stream().map((urlReport) -> urlReport.getScans()).map((scans) -> {
            System.out.println("---URL REPORT---");
            return scans;
        }).map((scans) -> {
            System.out.println("");
            return scans;
        }).forEach((scans) -> {
            scans.keySet().stream().forEach((scan) -> {
                URLScan report = scans.get(scan);
                System.out.println(scan + "\t:" + report.getReport());
            });
        });
    }
}

        
        

Retrieving IP address reports

Example:

        
package me.vighnesh.api.virustotal.examples;

import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.util.Arrays;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.IPAddressReport;
import me.vighnesh.api.virustotal.dao.IPAddressResolution;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class IpAddressReporter {

    public static void main(String[] args) throws UnknownHostException {
        String ip = "188.40.238.250";
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        IPAddressReport ipAddressReport = virusTotal.getIPAddressReport((Inet4Address) Inet4Address.getByName(ip));
        IPAddressResolution[] resolutions = ipAddressReport.getResolutions();
        System.out.println("---IP ADDRESS REPORT---");
        System.out.println("");
        for (IPAddressResolution resolution : resolutions) {
            System.out.println("Hostname : " + resolution.getHostName());
            System.out.println("Resolved : " + resolution.getLastResolved());
        }

        System.out.println("Verbose Message : " + ipAddressReport.getVerboseMessage());
        System.out.println("Response Code : " + ipAddressReport.getResponseCode());
        System.out.println("Detected Communicating Samples : " + Arrays.toString(ipAddressReport.getDetectedCommunicatingSamples()));
        System.out.println("Detected Downloading Samples : " + Arrays.toString(ipAddressReport.getDetectedDownloadedSamples()));
        System.out.println("Undetected Communicating Samples : " + Arrays.toString(ipAddressReport.getUndetectedCommunicatingSamples()));
        System.out.println("Undetected Communicating Samples : " + Arrays.toString(ipAddressReport.getUndetectedDownloadedSamples()));
        System.out.println("Detected URLS : " + Arrays.toString(ipAddressReport.getDetectedUrls()));
    }
}

        
        

Retrieving domain reports

Example:

        
package me.vighnesh.api.virustotal.examples;

import java.util.Arrays;
import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.DomainReport;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class DomainReporter {

    public static void main(String[] args) {
        String domain = "vighnesh.me";
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        DomainReport domainReport = virusTotal.getDomainReport(domain);
        System.out.println("---DOMAIN REPORT---");
        System.out.println("Response Code : " + domainReport.getResponseCode());
        System.out.println("Verbose Message : " + domainReport.getVerboseMessage());
        System.out.println("Detected Communicating Samples : " + Arrays.toString(domainReport.getDetectedCommunicatingSamples()));
        System.out.println("Detected Downloaded Samples : " + Arrays.toString(domainReport.getDetectedDownloadedSamples()));
        System.out.println("Resolutions : " + Arrays.toString(domainReport.getResolutions()));
        System.out.println("Undetected Communicating Samples : " + Arrays.toString(domainReport.getUndetectedCommunicatingSamples()));
        System.out.println("Undetected Downloading Samples : " + Arrays.toString(domainReport.getUndetectedDownloadedSamples()));
    }
}

        
        

Make comments on files and URLs

Example:

        
package me.vighnesh.api.virustotal.examples;

import me.vighnesh.api.virustotal.VirusTotalAPI;
import me.vighnesh.api.virustotal.dao.CommentStatus;

/**
 *
 * @author BVR vigneshb1210@gmail.com
 */
public class Comment {

    public static void main(String[] args) {
        VirusTotalAPI virusTotal = VirusTotalAPI.configure("YOUR API KEY");
        CommentStatus status = virusTotal.comment("SCAN ID", "Your Comment...");
        System.out.println("Verbose Message : " + status.getVerboseMsg());
        System.out.println("Response Code : " + status.getResponseCode());
    }
}

        
        

Comments

User Name

Description

Priority

Issue