Esempio n. 1
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            VirusTotal virusTotal = new VirusTotal(System.Configuration.ConfigurationManager.AppSettings["ApiKey"]);

            //Use HTTPS instead of HTTP
            virusTotal.UseTLS = true;


            string chosenfile = listView1.FocusedItem.SubItems[2].Text;;



            FileInfo fileInfo = new FileInfo(chosenfile);
            // File.WriteAllText(fileInfo.FullName, @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");
            string hashreport1 = String.Empty;

            //Check if the file has been scanned before.
            VirusTotalNET.Objects.Report fileReport = virusTotal.GetFileReport(fileInfo);
            bool         hasFileBeenScannedBefore   = fileReport.ResponseCode == ReportResponseCode.Present;
            DialogResult dialogresult = MessageBox.Show("File has been scan before: ", " hasFileBeenScannedBefore", MessageBoxButtons.YesNo);

            //If the file has been scanned before, the results are embedded inside the report.
            if (dialogresult == DialogResult.Yes)
            {
                PrintScan(fileReport);

                string str = Convert.ToString(fileReport.Positives);
                //string[] splitedStrings = str.Split('-');
                //string requestedValue = splitedStrings[0];
                //textBox4.Text = str;

                foreach (ScanEngine scan in fileReport.Scans)
                {
                    //string[] row1 = { scan.Name, Convert.ToString(scan.Detected) };
                    //listView1.Items.Add("Detect:").SubItems.AddRange(row1);
                    MessageBox.Show(scan.Result);
                }
            }
            else
            {
                VirusTotalNET.Objects.ScanResult fileResult = virusTotal.ScanFile(fileInfo);


                PrintScan(fileResult);

                string str = Convert.ToString(fileReport.Positives);
                //string[] splitedStrings = str.Split('-');
                // string requestedValue = splitedStrings[0];
                //textBox4.Text = str;
                //textBox4.Text = str;

                foreach (ScanEngine scan in fileReport.Scans)
                {
                    //string[] row1 = { scan.Name, Convert.ToString(scan.Detected) };
                    //listView1.Items.Add("Detect:").SubItems.AddRange(row1);

                    MessageBox.Show(scan.Result);
                }
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            VirusTotal virusTotal = new VirusTotal(System.Configuration.ConfigurationManager.AppSettings["ApiKey"]);

            //Use HTTPS instead of HTTP
            virusTotal.UseTLS = true;

            //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html
            string chosenfile = "";

            openFileDialog1.InitialDirectory = "C:";
            openFileDialog1.Title            = "insert file";
            openFileDialog1.FileName         = "";
            openFileDialog1.ShowDialog();
            chosenfile    = openFileDialog1.FileName;
            textBox1.Text = chosenfile;


            FileInfo fileInfo = new FileInfo(textBox1.Text);

            File.WriteAllText(fileInfo.FullName, @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");

            //Check if the file has been scanned before.
            VirusTotalNET.Objects.Report fileReport = virusTotal.GetFileReport(fileInfo);

            bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present;

            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
            {
                VirusTotalNET.Objects.ScanResult fileResult = virusTotal.ScanFile(fileInfo);
                PrintScan(fileResult);
            }

            Console.WriteLine();

            Report urlReport = virusTotal.GetUrlReport(ScanUrl);

            bool hasUrlBeenScannedBefore = urlReport.ResponseCode == ReportResponseCode.Present;

            Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No"));

            //If the url has been scanned before, the results are embedded inside the report.
            if (hasUrlBeenScannedBefore)
            {
                PrintScan(urlReport);
            }
            else
            {
                ScanResult urlResult = virusTotal.ScanUrl(ScanUrl);
                PrintScan(urlResult);
            }

            Console.WriteLine("Press a key to continue");
            Console.ReadLine();
        }