-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_nameserver_status.py
46 lines (39 loc) · 1.35 KB
/
get_nameserver_status.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
#!/usr/bin/python3
import dns.resolver
import json
import pprint
pp = pprint.PrettyPrinter(indent=4)
results = dict()
domains = ['ninja.geek.nz',
'parasite.net.nz',
'google.com',
'facebook.com',
'arstechnica.com',
'amazon.com']
def get_domain_nameserver_details(domain):
results = {'ns': [], 'additional': {}}
res = dns.resolver.Resolver(configure=True)
try:
ans = res.query(domain, 'NS')
except:
result['ns'] = None
else:
for rdata in ans:
results['ns'].append(rdata.target.to_text())
try:
additional = ans.response.additional
except:
pass
finally:
results['additional'] = {}
for rrset in additional:
if rrset.name.to_text() not in results['additional']:
results['additional'][rrset.name.to_text()] = {}
if rrset.rdtype not in results['additional'][rrset.name.to_text()]:
results['additional'][rrset.name.to_text()][str(rrset.rdtype)] = []
for item in rrset.items:
results['additional'][rrset.name.to_text()][str(rrset.rdtype)].append(item.address)
return results
for domain in domains:
details = get_domain_nameserver_details(domain)
pp.pprint( details )