Python code to get any Websites' DNS data via API.

DNS lookup use case.


Very often for webmasters and SEO professionals it is needed to check websites' DNS lookup data for certain domain and there is a very useful online service for web developers and SEO professionals on "WhoisXML API" that provides Domain & IP Data Intelligence for Greater Enterprise Security and RESTful APIs that we will use.

Using it's APIs you can perform many handy data requests, for example you can Websites' DNS lookup data for a certain website/domail or IP address - don't forget to get your API KEY. With one API call you will obtain ready to use parsed JSON file with a number of records associated with DNS: A record, mail servers (MX records), DNS servers (NS nameservers) and other items such as SPF records (TXT records).

Website DNS lookup.



This Python script below will use information from "WhoisXML API" and provide you a result in a JSON format without the need to use a web browser.
Getting websites' DNS lookup data can be easily automated now !



Python code to get Website DNS data via API:



# Website DNS Lookup API USE

import requests


website = 'weird-jokes.com'

APIKEY ='at_ZUVkrukr4UHznQq2j6dyv2VhFGWYV'
   

dnsInfoURL = f'https://www.whoisxmlapi.com/whoisserver/DNSService?apiKey={APIKEY}&domainName={website}&type=_all&outputFormat=JSON'

r = requests.get(dnsInfoURL)

dnsInfo = r.json()

print(f'DNS Info for {website} domain.\n')
dnsInfo

Website DNS data output:



DNS Info for weird-jokes.com domain.

{'DNSData': {'domainName': 'weird-jokes.com',
  'types': [-1],
  'dnsTypes': '_all',
  'audit': {'createdDate': '2022-09-07 09:50:43 UTC',
   'updatedDate': '2022-09-07 09:50:43 UTC'},
  'dnsRecords': [{'type': 16,
    'dnsType': 'TXT',
    'name': 'weird-jokes.com.',
    'ttl': 3600,
    'rRsetType': 16,
    'rawText': 'weird-jokes.com.\t3600\tIN\tTXT\t"v=spf1 ip4:31.31.198.90 a mx ~all"',
    'strings': ['v=spf1 ip4:31.31.198.90 a mx ~all']},
   {'type': 1,
    'dnsType': 'A',
    'name': 'weird-jokes.com.',
    'ttl': 3600,
    'rRsetType': 1,
    'rawText': 'weird-jokes.com.\t3600\tIN\tA\t194.67.91.32',
    'address': '194.67.91.32'},
   {'type': 2,
    'dnsType': 'NS',
    'name': 'weird-jokes.com.',
    'additionalName': 'ns5.hosting.reg.ru.',
    'ttl': 3600,
    'rRsetType': 2,
    'rawText': 'weird-jokes.com.\t3600\tIN\tNS\tns5.hosting.reg.ru.',
    'target': 'ns5.hosting.reg.ru.'},
   {'type': 2,
    'dnsType': 'NS',
    'name': 'weird-jokes.com.',
    'additionalName': 'ns6.hosting.reg.ru.',
    'ttl': 3600,
    'rRsetType': 2,
    'rawText': 'weird-jokes.com.\t3600\tIN\tNS\tns6.hosting.reg.ru.',
    'target': 'ns6.hosting.reg.ru.'},
   {'type': 6,
    'dnsType': 'SOA',
    'name': 'weird-jokes.com.',
    'ttl': 3600,
    'rRsetType': 6,
    'rawText': 'weird-jokes.com.\t3600\tIN\tSOA\tdnsadmin.hosting.reg.ru. root.dnsadmin.hosting.reg.ru. 2022062600 3600 3600 604800 86400',
    'admin': 'root.dnsadmin.hosting.reg.ru.',
    'host': 'dnsadmin.hosting.reg.ru.',
    'expire': 604800,
    'minimum': 86400,
    'refresh': 3600,
    'retry': 3600,
    'serial': 2022062600},
   {'type': 15,
    'dnsType': 'MX',
    'name': 'weird-jokes.com.',
    'additionalName': 'mail.weird-jokes.com.',
    'ttl': 3600,
    'rRsetType': 15,
    'rawText': 'weird-jokes.com.\t3600\tIN\tMX\t20 mail.weird-jokes.com.',
    'priority': 20,
    'target': 'mail.weird-jokes.com.'},
   {'type': 15,
    'dnsType': 'MX',
    'name': 'weird-jokes.com.',
    'additionalName': 'mail.weird-jokes.com.',
    'ttl': 3600,
    'rRsetType': 15,
    'rawText': 'weird-jokes.com.\t3600\tIN\tMX\t10 mail.weird-jokes.com.',
    'priority': 10,
    'target': 'mail.weird-jokes.com.'}]}}




See also related topics: