-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdnsdbext.py
More file actions
35 lines (29 loc) · 713 Bytes
/
dnsdbext.py
File metadata and controls
35 lines (29 loc) · 713 Bytes
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
#!/usr/bin/python
from BeautifulSoup import BeautifulSoup
import sys
import urllib2
import requests
import socket
if len(sys.argv) == 2:
domain = sys.argv[1]
else:
print "Error: " + sys.argv[0] + " <domain>"
sys.exit(0)
def get_ips_for_host(host):
try:
ips = socket.gethostbyname_ex(host)
except socket.gaierror:
ips=[]
return ips
url = "http://" + domain + ".dnsdb.org/"
response = urllib2.urlopen(url)
html = response.read()
soup = BeautifulSoup(html)
for link in soup.findAll('a'):
host = link.contents[0]
ips = get_ips_for_host(host)
if len(ips) > 1:
ip = ips[2]
print host + "," + ','.join(map(str, ip))
else:
print host