Skip to content

Commit a0a0f3a

Browse files
added reverse lookup script
1 parent 0ace707 commit a0a0f3a

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,16 @@ Happy scripting!
6767

6868
#### Requirements :
6969
Python 3.5+
70-
70+
71+
### RevereLookup :
72+
Takes an input list of ip addresses and does a reverse lookup for dns information and org information and writes to a csv file.
73+
74+
#### Requirements :
75+
Python 3+, Requests
76+
7177
### WebsiteMonitor :
7278
Monitor a website for a seach term. When it shows up, send yourself an e-mail.
7379

7480
#### Requirements :
7581
Python 3.5+, Requests
82+

ReverseLookup/ip_list.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
8.8.8.8
2+
1.1.1.1
3+
1.0.0.1

ReverseLookup/reverse_lookup.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
This script retrieves information about IP addresses an generates a CSV file out of it
3+
4+
Put a list of IPs in ip_list.txt in current directory (plain IPs, one per line)
5+
CSV output is written to out_file.csv in current directory
6+
7+
Lookups are retrieved from extreme-ip-lookup.com website
8+
"""
9+
import csv
10+
import getpass
11+
import socket
12+
13+
import requests
14+
from requests.packages.urllib3.exceptions import InsecureRequestWarning
15+
16+
session = requests.session()
17+
session.verify = False
18+
19+
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
20+
21+
with open("out_file.csv", mode="w", newline='') as out_file, open('ip_list.txt') as ip_list:
22+
out_file.write("SEP=,\n")
23+
24+
csvwriter = csv.writer(out_file)
25+
csvwriter.writerow([
26+
"IP",
27+
"Name",
28+
"Location",
29+
"LookupName",
30+
"ISP",
31+
"Organization",
32+
])
33+
34+
for ip in ip_list.readlines():
35+
ip = ip.strip()
36+
try:
37+
hostname, aliaslist, ipaddrlist = socket.gethostbyaddr(ip)
38+
except:
39+
hostname = ''
40+
41+
try:
42+
response = session.get("https://extreme-ip-lookup.com/json/%s" % ip)
43+
response.raise_for_status()
44+
ip_data = response.json()
45+
46+
location = ip_data['country'] + ' ' + ip_data['continent']
47+
ipName = ip_data['ipName']
48+
isp = ip_data['isp']
49+
org = ip_data['org']
50+
except:
51+
location = ''
52+
ipName = ''
53+
isp = ''
54+
org = ''
55+
56+
print('%-20s%s' % (ip, hostname))
57+
csvwriter.writerow([
58+
ip,
59+
hostname,
60+
location,
61+
ipName,
62+
isp,
63+
org,
64+
])

0 commit comments

Comments
 (0)