-
Notifications
You must be signed in to change notification settings - Fork 1
/
WhoisIP.py
34 lines (27 loc) · 976 Bytes
/
WhoisIP.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
from ipwhois import IPWhois
import csv
__outFile__ = raw_input("Provide your output File Path with .csv file name: ")
try:
c = csv.writer(open(__outFile__, "wb"))
except Exception as error:
print "Error in output file", error
else:
c.writerow(['IP Address', 'Country', 'State', 'City', 'Description', 'Name', 'Emails', 'Range'])
__inputFile__ = raw_input("Enter the list of IP Address file path: ")
try:
fileOpne = open(__inputFile__, 'r')
lines = fileOpne.read().strip().split()
for ip in lines:
obj = IPWhois(ip)
out = obj.lookup()
f = out["nets"][0]['city']
a = out["nets"][0]['country']
g = out["nets"][0]['description']
b = out["nets"][0]['emails']
h = out["nets"][0]['name']
rangs = out["nets"][0]['range']
e = out["nets"][0]['state']
c.writerow([ip, a, e, f, g, h, b, rangs])
fileOpne.close()
except Exception as an:
print "Error in input file :", an