-
-
Save yukkeorg/43de0c7cce8c3ab0773590ae23a18f72 to your computer and use it in GitHub Desktop.
Terateil 118442
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VirusTotalのScan URL API使ってみる検証プログラム | |
# 実行方法: | |
# for Linux/Mac(Bash): | |
# $ VT_APIKEY=<apikey> python3 vt_scanurl.py <URL> | |
# for Windows(cmd.exe) | |
# > set VT_APIKEY=<apikey> | |
# > python3 vt_scanurl.py <URL> | |
import sys | |
import os | |
import urllib.request | |
import urllib.parse | |
import json as _json | |
import pprint | |
import time | |
def main(): | |
if len(sys.argv) != 2: | |
print("Not specified URL") | |
return 1 | |
url = sys.argv[1] | |
APIKEY = os.environ.get("VT_APIKEY") | |
if APIKEY is None: | |
print("Can not read VT_APIKEY environment variable") | |
return 2 | |
# Call /url/scan API | |
print("Waiting response 'POST /url/scan'") | |
params = urllib.parse.urlencode({"apikey": APIKEY, "url": url}).encode('utf-8') | |
response = urllib.request.urlopen("https://www.virustotal.com/vtapi/v2/url/scan", data=params) | |
json = _json.loads(response.read().decode('utf-8')) | |
pprint.pprint(json) | |
if not json: | |
print("Error in calling /url/scan API") | |
return 3 | |
# Save scan_id from /url/scan API response | |
scan_id = json["scan_id"] | |
# wait 10 secs | |
print("Wait 10 seconds...") | |
time.sleep(10) | |
# Call /url/report API | |
print("Waiting response 'GET /url/report'") | |
query = urllib.parse.urlencode({"apikey": APIKEY, "resource": scan_id}) | |
response = urllib.request.urlopen("https://www.virustotal.com/vtapi/v2/url/report?" + query) | |
json = _json.loads(response.read().decode('utf-8')) | |
pprint.pprint(json) | |
if not json: | |
print("Error in calling /url/report API") | |
return 4 | |
return 0 | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment