VirusTotal api 在 python 中的 URL,域名使用

URL

发送并扫描URL

首先发送扫描一个url,要向https://www.virustotal.com/vtapi/v2/url/scan
发送一个http post 请求,

其中api 接受请求中的两个参数:

url:要扫描的url

apikey: 注册virus用户,登录后得到的public key。这是使用api的关键。
当进行批量扫描时候,其中url参数接受一个最大长度为4的urls列表,并且每个url之间以’\n’作为间隔符

如果请求速率超过了api限定速率,将被返回http 204状态码,若尝试执行没有所需权限的函数调用,将被返回http 403异常

e.g.

parameters ={“url”:”http://www.virustotal.com\nhttp://www.virustotal.com”,”apikey”: your api-key}

def scanURL(urls,apikey):
    print urls
    url = 'https://www.virustotal.com/vtapi/v2/url/scan'
    parameters = {"url":urls,"apikey":apikey}
    data = urllib.urlencode(parameters)
    try:
        req = urllib2.Request(url, data)
        response = urllib2.urlopen(req)
        json = response.read()
        #print json
    except urllib2.HTTPError, error:
        print 'HTTPError--code:'+str(error.code)
    except urllib2.URLError,error:
        print 'URLError--reason:'+str(error.reason)

result

上图为返回的json数据:

参数解读:

scan_id: URL scan report retrieving API 中用于查找扫描报告所需参数
response_code :若搜索项不在VirusTotals的收录中,将被返回0;若请求项仍入队请求分析,将被返回-2;若请求项存在并且可被检索,将返回1。
verbose_msg:提供有关response_code 的详细信息。


检索URL扫描报告

检索一个url的扫描报告,要向 http://www.virustotal.com/vtapi/v2/url/report 提交一个post请求

http post 请求参数:

resource:若给定url,将检索给定的URL的最新报告。你也可以指定SCAN_ID访问对应的报告。同时,也可以指定由哈希和scan_ids组合的CSV列表,用来执行批请求(标准速率同样是最多4个请求)。当多次发送时,scan_ids或URL必须通过新的行字符分隔。

scan(可选参数):当设置为“1”,将自动提交URL进行分析,如果在VirusTotal服务的数据库中没有发现已有的报告,此时,返回的结果将包含一个SCAN_ID字段可用于查询稍后的分析报告。

apikey:你的API密钥。

def reportURL(urls,apikey):
    print urls
    url = "https://www.virustotal.com/vtapi/v2/url/report"
    parameters = {"resource": urls, "apikey": apikey,"scan":1}
    data = urllib.urlencode(parameters)
    try:
        req = urllib2.Request(url, data)
        response = urllib2.urlopen(req)
        json = response.read()
        #print json
    except urllib2.HTTPError, error:
        print 'HTTPError--code:'+str(error.code)
    except urllib2.URLError,error:
        print 'URLError--reason:'+str(error.reason)

result

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章