-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvtChecker_v1.1.py
More file actions
108 lines (83 loc) · 2.78 KB
/
vtChecker_v1.1.py
File metadata and controls
108 lines (83 loc) · 2.78 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import requests
import datetime as dt
import time
from csv import reader
import pandas as pd
import json
'''*****To use this script, please do the following:
STEP 1: Enter your file name that contains your list of IP's, be sure to place it in
between the quotes i.e. file_name = 'ip_list.csv'
STEP 2: Enter your VirusTotal Api Key below i.e. api_key = '1234567890abcdefghijklmnopqrstuv'
******'''
# Enter your file name and api key in the variables below:
file_name = '<<**ENTER YOUR FILE NAME HERE**>>'
api_key = '<<**ENTER YOUR API KEY HERE**>>'
def intake_file(file):
# Open and read IP list
open_file = open(file)
read_file = reader(open_file)
ip_list = list(read_file)
return ip_list
# Performs a lookup of each ip in list to VirustTotal, free API Key limits # of request within one min
def vt_caller():
count = 0
limit = 4
ip_list = intake_file(file_name)
results = []
print('The program is loading up your ', str(len(ip_list)), ' IP addresses')
time.sleep(15)
api = api_key
u = 'https://www.virustotal.com/vtapi/v2/ip-address/report'
print('looks like there are ', len(ip_list), ' IP\'s to check')
for ip in ip_list:
count += 1
print('Checking IP: ', ip)
p = {'apikey': api, 'ip': ip}
r = requests.get(u, p)
results.append(r.json())
if count == limit:
print("you're using a free api key - this may take some time")
time.sleep(65)
print('ok, back to work....')
count = 0
data = [['ip', 'owner', 'country', '#_detected_urls']]
c = 0
t = len(ip_list)
# Parses json responses from VirusTotal
for i in results:
if 'as_owner' in i:
as_owner = i['as_owner']
else:
as_owner = 'none'
if 'country' in i:
country = i["country"]
else:
country = 'none'
if 'detected_urls' in i:
detected_urls = i['detected_urls']
num_of_detections = 0
for d in detected_urls:
print(d)
num_of_detections += 1
else:
detected_urls = 'none'
ip = ip_list[c]
data.append([ip, as_owner, country, num_of_detections])
c += 1
return data
def vt_results():
data = vt_caller()
# creates a dataframe of results
df = pd.DataFrame(data)
print("\n\nHere's your Data, a CSV has also been created name ipvtresults-[timestamp].csv")
for i in data:
print(i)
# Creates a csv of results
mt = dt.datetime.now()
ft = str(mt.strftime('%H-%M-%S-%f'))
outfile = 'ip_vtresults-' + ft + '.csv'
output = df.to_csv(outfile)
return output
print("** Welcome to the Virustotal Checker for free API Keys!!** \n")
intake_file(file_name)
vt_results()