-
Notifications
You must be signed in to change notification settings - Fork 176
/
virustotal.py
executable file
·71 lines (50 loc) · 1.84 KB
/
virustotal.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
from netaddr import *
import requests
import json
import time
import os
import argparse
virus_total_api_key = os.environ['VIRUS_TOTAL_API_KEY']
def process(cidr, logfile):
total_found_domains = 0
ips = IPSet([cidr])
for ip in ips:
print("\n[+] Resolving IP: {}".format(ip))
found_domains = 0
url = 'https://www.virustotal.com/vtapi/v2/ip-address/report?apikey={}&ip={}'.format(
virus_total_api_key, str(ip))
resp = requests.get(url)
if resp.status_code == 200:
domains = json.loads(resp.text)
if (domains['response_code'] == 0):
print("[-] Empty response for {}".format(str(ip)))
time.sleep(15)
continue
f = open(logfile, 'a')
for d in domains['resolutions']:
print('>>> {}'.format(d['hostname']))
found_domains = found_domains + 1
f.write("{}\n".format(d['hostname']))
print("[+] Found {} domain(s) on {}".format(found_domains, str(ip)))
print("[+] Waiting 15 sec. until next request (VirusTotal API restriction)")
total_found_domains = total_found_domains + found_domains
f.close()
else:
print("[-] Empty response for {}".format(str(ip)))
time.sleep(15)
print("\n\n[+] Done, found {} in total".format(total_found_domains))
def main():
parser = argparse.ArgumentParser()
logfile = 'virustotal.domains'
parser.add_argument(
"-c", "--cidr", help="Network CIDR")
parser.add_argument(
"-o", "--output", help="Log filename (default - virustotal.domains)")
args = parser.parse_args()
if args.output:
logfile = args.output
if args.cidr:
process(args.cidr, logfile)
if __name__ == "__main__":
main()