Ejemplo n.º 1
0
    public async Task ScanVeryLargeFile()
    {
        VirusTotal.Timeout = TimeSpan.FromSeconds(500);
        ScanResult result = await VirusTotal.ScanLargeFileAsync(new byte[VirusTotal.LargeFileSizeLimit], TestData.TestFileName);

        Assert.Equal(ScanFileResponseCode.Queued, result.ResponseCode);
    }
Ejemplo n.º 2
0
        public static async Task GetScanReportForFile()
        {
            VirusTotal virusTotal = new VirusTotal("");

            //Use HTTPS instead of HTTP
            virusTotal.UseTLS  = true;
            virusTotal.Timeout = TimeSpan.FromSeconds(500);

            try
            {
                FileReport fileReport = await virusTotal.GetFileReportAsync(Program.fileName);

                bool hasFileBeenScannedBefore = fileReport.ResponseCode == FileReportResponseCode.Present;
                if (!hasFileBeenScannedBefore)
                {
                    Console.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No"));
                }

                //If the file has been scanned before, the results are embedded inside the report.
                if (hasFileBeenScannedBefore)
                {
                    PrintScan(fileReport);
                }
                else
                {
                    if (!File.Exists(Program.filePath))
                    {
                        throw new FileNotFoundException("The file was not found.", Program.filePath);
                    }

                    Stream     fs         = File.OpenRead(Program.filePath);
                    ScanResult fileResult = await virusTotal.ScanFileAsync(fs, Program.fileName);

                    PrintScan(fileResult);
                }
            }
            catch (VirusTotalNet.Exceptions.SizeLimitException)
            {
                try
                {
                    virusTotal.RestrictSizeLimits = false;

                    Stream     fs         = File.OpenRead(Program.filePath);
                    ScanResult fileResult = await virusTotal.ScanLargeFileAsync(fs, Program.fileName);
                }
                catch (VirusTotalNet.Exceptions.SizeLimitException)
                {
                    Console.WriteLine("VirusTotalNet.Exceptions.SizeLimitException");
                    DBConnect.InsertnotvtscannedTable(Program.appName, Program.fileName, "", "SizeLimitException");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    DBConnect.InsertnotvtscannedTable(Program.appName, Program.fileName, "", ex.Message);
                }
            }
            catch (VirusTotalNet.Exceptions.RateLimitException)
            {
                Console.WriteLine("VirusTotalNet.Exceptions.RateLimitException");
                DBConnect.InsertnotvtscannedTable(Program.appName, Program.fileName, "", "RateLimitException");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                DBConnect.InsertnotvtscannedTable(Program.appName, Program.fileName, "", ex.Message);
            }
        }