-
Notifications
You must be signed in to change notification settings - Fork 0
/
VTService.py
49 lines (38 loc) · 1.66 KB
/
VTService.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
39
40
41
42
43
44
45
46
47
48
49
import requests
import time
class VTService:
def rescan_virus(self, resource, api_key):
params = {'apikey': api_key, 'input': resource}
response = requests.post('https://www.virustotal.com/vtapi/v2/file/rescan',
params=params)
json_response = response.json()
print(json_response)
return json_response
def report_virus(self, resource, api_key):
params = {'apikey': api_key, 'resource': resource}
headers = {
"Accept-Encoding": "gzip, deflate",
"User-Agent": "gzip, My Python requests library example client or username"
}
response = requests.get('https://www.virustotal.com/vtapi/v2/file/report',
params=params, headers=headers)
json_response = response.json()
# print(json_response)
return json_response
def ask_to_virus_total_service(self, resource, api_key):
try:
return self.report_virus(resource, api_key)
except Exception as e:
print("ask_to_virus_total_service..." + str(e))
time.sleep(3)
return self.ask_to_virus_total_service(resource, api_key)
def fetch_engine_values(self, resource, api_key):
result_str = resource + ":"
response = self.ask_to_virus_total_service(resource, api_key)
scans = response.get("scans")
for engine in scans:
engine_info = scans.get(engine)
if engine_info.get("detected") is True:
tmp_str = str(engine_info.get("result"))
result_str = result_str + engine + "_" + tmp_str + ","
return result_str