Advertisement
steve-shambles-2109

185-Get dns records of url

Oct 22nd, 2019
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. """
  2. Python code snippets vol 37:
  3. 185-Get dns records of url
  4. stevepython.wordpress.com
  5.  
  6. Requirements:
  7. pip3 install dnspython==1.15.0
  8.  
  9. Source:
  10. https://gist.github.com/akshaybabloo/2a1df455e7643926739e934e910cbf2e
  11. """
  12.  
  13. import dns.resolver
  14.  
  15. def get_records(domain):
  16.     """
  17.    Get all the records associated to domain parameter.
  18.    :param domain:
  19.    :return:
  20.    """
  21.     ids = [
  22.         'NONE',
  23.         'A',
  24.         'NS',
  25.         'MD',
  26.         'MF',
  27.         'CNAME',
  28.         'SOA',
  29.         'MB',
  30.         'MG',
  31.         'MR',
  32.         'NULL',
  33.         'WKS',
  34.         'PTR',
  35.         'HINFO',
  36.         'MINFO',
  37.         'MX',
  38.         'TXT',
  39.         'RP',
  40.         'AFSDB',
  41.         'X25',
  42.         'ISDN',
  43.         'RT',
  44.         'NSAP',
  45.         'NSAP-PTR',
  46.         'SIG',
  47.         'KEY',
  48.         'PX',
  49.         'GPOS',
  50.         'AAAA',
  51.         'LOC',
  52.         'NXT',
  53.         'SRV',
  54.         'NAPTR',
  55.         'KX',
  56.         'CERT',
  57.         'A6',
  58.         'DNAME',
  59.         'OPT',
  60.         'APL',
  61.         'DS',
  62.         'SSHFP',
  63.         'IPSECKEY',
  64.         'RRSIG',
  65.         'NSEC',
  66.         'DNSKEY',
  67.         'DHCID',
  68.         'NSEC3',
  69.         'NSEC3PARAM',
  70.         'TLSA',
  71.         'HIP',
  72.         'CDS',
  73.         'CDNSKEY',
  74.         'CSYNC',
  75.         'SPF',
  76.         'UNSPEC',
  77.         'EUI48',
  78.         'EUI64',
  79.         'TKEY',
  80.         'TSIG',
  81.         'IXFR',
  82.         'AXFR',
  83.         'MAILB',
  84.         'MAILA',
  85.         'ANY',
  86.         'URI',
  87.         'CAA',
  88.         'TA',
  89.         'DLV',
  90.     ]
  91.  
  92.     for a in ids:
  93.         try:
  94.             answers = dns.resolver.query(domain, a)
  95.             for rdata in answers:
  96.                 print(a, ':', rdata.to_text())
  97.  
  98.         except Exception as e:
  99.             print(e)  # or pass
  100.  
  101. if __name__ == '__main__':
  102.     get_records('python.com')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement