Skip to content

KHAPCHI.COM

One stick to rule all staffs!

  • Home
  • Technology
  • Tools
  • About
  • Toggle search form
  • Install and configure Squid3 for Ubuntu20.04 for known hosts – IP Access Uncategorized
  • Begin! Uncategorized
  • How to store JSON response from an API to MySQL table? Technology
  • How to Query any REST API using Python3 easy. Technology
  • Store JSON response from API as separate columns in MySQL table? Technology
  • Multilib problems while using yum. Technology
  • Python3 regular expression to fetch Domains from a string or Paragraph. Technology
  • How to make DNS lookup of an IP or Domain using Python3. Technology

How to fetch all DNS records of a Domain using Python3.

Posted on December 8, 2022December 8, 2022 By Khapchi No Comments on How to fetch all DNS records of a Domain using Python3.

To fetch all DNS records of a domain using Python3, you can use the dnspython module, which provides functions for working with DNS records. The dnspython module allows you to fetch the DNS records of a domain and access the individual fields of each record, such as the type of record, the TTL (time to live), and the data associated with the record.

Here is an example of how you might use the dnspython module to fetch all DNS records of a domain:

import dns.resolver

# Fetch all DNS records for a domain
domain = "www.google.com"
answers = dns.resolver.query(domain, "ANY")

# Print the DNS records
for rdata in answers:
    print("Type:", rdata.rdtype)
    print("TTL:", rdata.ttl)
    print("Data:", rdata.to_text())

In this example, we import the dns.resolver module and use the query() function to fetch all DNS records for the domain “www.google.com“. The query() function returns a list of dns.rdata.Rdata objects, which represent individual DNS records. We iterate over this list of records and print the type, TTL, and data of each record to the console.

You can also specify the type of DNS record that you want to fetch, such as A, MX, or CNAME, by passing the record type as the second argument to the query() function. For example, the following code will only fetch A records for the domain:

import dns.resolver

# Fetch A records for a domain
domain = "www.google.com"
answers = dns.resolver.query(domain, "A")

# Print the A records
for rdata in answers:
    print("Type:", rdata.rdtype)
    print("TTL:", rdata.ttl)
    print("Data:", rdata.to_text())

In this example, we use the query() function to fetch only A records for the domain “www.google.com“, and then print the type, TTL, and data of each record to the console.

Note that the dnspython module requires that you have a working DNS server on your network in order to perform DNS lookups. If you do not have a DNS server configured, you will need to set one up before you can use the dnspython module.

Technology Tags:dnspython, Python3, rdata

Post navigation

Previous Post: How to make DNS lookup of an IP or Domain using Python3.
Next Post: How to Query any REST API using Python3 easy.

Related Posts

  • How to make DNS lookup of an IP or Domain using Python3. Technology
  • Store JSON response from API as separate columns in MySQL table? Technology
  • How to store JSON response from an API to MySQL table? Technology
  • Prepare a Linux server for first use. Technology
  • Python3 regular expression to fetch Domains from a string or Paragraph. Technology
  • How to connect to Local MySQL Db using Python3 Technology

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Recent Posts

  • Python3 regular expression to fetch Domains from a string or Paragraph.
  • Store JSON response from API as separate columns in MySQL table?
  • How to store JSON response from an API to MySQL table?
  • How to Query any REST API using Python3 easy.
  • How to fetch all DNS records of a Domain using Python3.

Recent Comments

    Archives

    • December 2022
    • July 2020
    • May 2020

    Categories

    • Technology
    • Uncategorized

    Archives

    • December 2022
    • July 2020
    • May 2020
    • Install and configure Squid3 for Ubuntu20.04 for known hosts – IP Access Uncategorized
    • Begin! Uncategorized
    • How to make DNS lookup of an IP or Domain using Python3. Technology
    • Prepare a Linux server for first use. Technology
    • How to connect to Local MySQL Db using Python3 Technology
    • How to store JSON response from an API to MySQL table? Technology
    • Python3 regular expression to fetch Domains from a string or Paragraph. Technology
    • 7 Commands to know your Linux Server Technology

    Copyright © 2025 KHAPCHI.COM.

    Powered by PressBook News WordPress theme