-
Notifications
You must be signed in to change notification settings - Fork 68
/
reverse-dns-scanner.py
executable file
·64 lines (47 loc) · 1.44 KB
/
reverse-dns-scanner.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
#!/usr/bin/python3
import sys
import socket
from random import randint
if len(sys.argv) < 2:
print(sys.argv[0] + ": <start_ip>-<stop_ip>")
sys.exit(1)
def get_ips(start_ip, stop_ip):
ips = []
tmp = []
for i in start_ip.split('.'):
tmp.append("%02X" % int(i))
start_dec = int(''.join(tmp), 16)
tmp = []
for i in stop_ip.split('.'):
tmp.append("%02X" % int(i))
stop_dec = int(''.join(tmp), 16)
while(start_dec < stop_dec + 1):
bytes = []
bytes.append(str(int(start_dec / 16777216)))
rem = start_dec % 16777216
bytes.append(str(int(rem / 65536)))
rem = rem % 65536
bytes.append(str(int(rem / 256)))
rem = rem % 256
bytes.append(str(rem))
ips.append(".".join(bytes))
start_dec += 1
return ips
def dns_reverse_lookup(start_ip, stop_ip):
ips = get_ips(start_ip, stop_ip)
while len(ips) > 0:
i = randint(0, len(ips) - 1)
lookup_ip = str(ips[i])
resolved_name = None
try:
resolved_name = socket.gethostbyaddr(lookup_ip)[0]
except socket.herror as e:
# Ignore unknown hosts
pass
except socket.error as e:
print(str(e))
if resolved_name:
print(lookup_ip + ":\t" + resolved_name)
del ips[i]
start_ip, stop_ip = sys.argv[1].split('-')
dns_reverse_lookup(start_ip, stop_ip)