如何使用C#中的VirusTotal.NET库查找文件是否被病毒感染?

时间:2019-01-14 05:45:32

标签: c# virus-scanning

我当前在C#MVC项目中使用VirusTotal.NET nuget软件包来扫描上传的文件。我正在使用此处给出的相同示例https://github.com/Genbox/VirusTotal.NET

[name-98, name-99, name-100]

我正在将上载文件的字节数组加载到上述代码中的VirusTotal virusTotal = new VirusTotal("YOUR API KEY HERE"); //Use HTTPS instead of HTTP virusTotal.UseTLS = true; //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html byte[] eicar = Encoding.ASCII.GetBytes(@"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"); //Check if the file has been scanned before. FileReport report = await virusTotal.GetFileReportAsync(eicar); Console.WriteLine("Seen before: " + (report.ResponseCode == FileReportResponseCode.Present ? "Yes" : "No")); 变量中。根据给定的示例,它将提供是否已扫描文件。但是我真正需要的是文件是否被感染。谁能给我建议解决方案?

1 个答案:

答案 0 :(得分:6)

检出UrlReport类,您获得的报告不仅包含代码示例中的响应代码,还具有更多信息。有3个有趣的字段:

picked_date = widgets.DatePicker( 
    description='Pick a Date',
    disabled=False
)
picked_date

df.loc[picked_date.value,"Manure"]=1

这可能会为您提供所需的结果。 VirusTotal实际上会返回多个扫描引擎的结果,其中一些可能检测到病毒,而另一些可能未检测到。

/// <summary>
/// How many engines flagged this resource.
/// </summary>
public int Positives { get; set; }

/// <summary>
/// The scan results from each engine.
/// </summary>
public Dictionary<string, UrlScanEngine> Scans { get; set; }

/// <summary>
/// How many engines scanned this resource.
/// </summary>
public int Total { get; set; }

您可以对数据进行任何操作,例如计算百分比:

Console.WriteLine($"{report.Positives} out of {report.Total} scan engines detected a virus.");

或者只是将大多数阳性扫描引擎结果视为整体阳性结果:

var result = 100m * report.Positives / report.Total;
Console.WriteLine($"{result}% of scan engines detected a virus.");