I have the simple python code for grabbing NS
records of a domain:
#!/usr/bin/python
import socket
import dns.resolver
domain = 'google.com'
resp = dns.resolver.query(domain, 'NS')
for d in resp:
ns = d.to_text()
nsip = socket.gethostbyname(ns)
print ns, nsip
And sample result is something like:
ns2.google.com. 216.239.34.10
ns1.google.com. 216.239.32.10
ns3.google.com. 216.239.36.10
ns4.google.com. 216.239.38.10
ns5.google.com. 216.5.5.5
But I want to remove printing repetitive ips from the output like so:
IP: 216.239.32.10
ns2.google.com., ns1.google.com., ns3.google.com., ns4.google.com.
IP: 216.5.5.5
ns5.google.com.
How can I do that?