【问题标题】:VirusTotal Api Usage? [closed]VirusTotal API 使用情况? [关闭]
【发布时间】:2012-09-12 16:10:52
【问题描述】:

所以我得到了这个

public class VirusTotal
{
    public string APIKey;
    string scan = "https://www.virustotal.com/api/scan_file.json";
    string results = "https://www.virustotal.com/api/get_file_report.json";

    public VirusTotal(string apiKey)
    {
        ServicePointManager.Expect100Continue = false;
        APIKey = apiKey;
    }

    public string Scan(string file)
    {
        var v = new NameValueCollection();
        v.Add("key", APIKey);
        var c = new WebClient() { QueryString = v };
        c.Headers.Add("Content-type", "binary/octet-stream");
        byte[] b = c.UploadFile(scan, "POST", file);
        var r = ParseJSON(Encoding.Default.GetString(b));
        if (r.ContainsKey("scan_id"))
        {
            return r["scan_id"];
        }
        throw new Exception(r["result"]);
    }

    public string GetResults(string id)
    {
        Clipboard.SetText(id);
        var data = string.Format("resource={0}&key={1}", id, APIKey);
        var c = new WebClient();
        string s = c.UploadString(results, "POST", data);
        var r = ParseJSON(s);
        foreach (string str in r.Values)
        {
            MessageBox.Show(str);
        }
        if (r["result"] != "1")
        {
            throw new Exception(r["result"]);
        }
        return s;
    }

    private Dictionary<string, string> ParseJSON(string json)
    {
        var d = new Dictionary<string, string>();
        json = json.Replace("\"", null).Replace("[", null).Replace("]", null);
        var r = json.Substring(1, json.Length - 2).Split(',');
        foreach (string s in r)
        {
            d.Add(s.Split(':')[0], s.Split(':')[1]);
        }
        return d;
    }
}

但是如果我输入 url 我会认为它的扫描,但是我如何检索扫描回来并开始扫描过程

抱歉,我是 api 新手,我并没有真正得到 webclient 的帮助

【问题讨论】:

  • 不是给它一个 url 来扫描,而是发出一个包含该文件的 post 请求(请参阅这个简单的 PHP virustotal api:thewebhelp.com/php/scripts/virustotal-php-api),然后您再次请求该文件的报告。

标签: c#


【解决方案1】:

您实际上不需要在此处指定任何 URL。

当您上传文件进行扫描时,您会返回由 VirusTotal 生成的唯一请求 ID。该 ID 是 Scan 函数的返回值。如果您将此值存储在一个变量中,然后在调用 GetResults 时指定它,那么您应该会得到结果。

代码如下所示:

VirusTotal vtObject = new VirusTotal("%Your_API_key_here%");
string resultID = vtObject.Scan("%your_file_name_here%");
string results = vtObject.GetResults(resultID);

还请注意,文件扫描需要一些时间,因此您很可能会在results 中收到类似“您的文件已排队等待扫描,稍后再回来”的信息。您可能需要在一段时间后致电GetResults,以便在 VT 处理您的文件后获取实际的扫描数据。

【讨论】:

  • 我还是很困惑,我把我的 url 放在你的文件名里 + 我的 api 密钥放在你的 api 密钥里
  • 您想从 url 扫描文件吗?然后您需要: 1) 将文件下载到本地 HDD 并在调用 Scan 时指定路径或 2) 使用 VT API 的另一个函数,专门设计用于扫描 URL(参见 documentation,部分“发送和扫描 URL")
  • 我想扫描一个 url,我不想使用 webbrowser,我希望它能够检测到它是否被检测到
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多