-
Notifications
You must be signed in to change notification settings - Fork 3
/
VirusTotalCheck.py
38 lines (33 loc) · 1.08 KB
/
VirusTotalCheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
"""
ONLY ACCEPTS HTTP://
"""
def format_url_for_virustotal(url):
if url.startswith('https://'):
url = 'http://' + url[len('https://'):]
elif not url.startswith('http://'):
url = 'http://' + url
return url
def virus_total_urlanalysis(original_url, api_key):
url = format_url_for_virustotal(original_url)
headers = {
'x-apikey': api_key
}
response = requests.post('https://www.virustotal.com/api/v3/urls', headers=headers, data={'url': url})
if response.status_code == 200:
result = response.json()
url_id = result['data']['id']
return url_id
else:
print(f"Error submitting URL for analysis: {response.status_code}")
return None
def get_analysis_report(url_id, api_key):
headers = {
'x-apikey': api_key
}
response = requests.get(f'https://www.virustotal.com/api/v3/analyses/{url_id}', headers=headers)
if response.status_code == 200:
result = response.json()
return result
else:
return f"Error: Code Response: {response.status_code}"