🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now β†’
Menu

Categories

DNS Record Checking with Python: Query A, MX, NS, TXT Records (Free CLI Tool)

DNS Record Checking with Python: Query A, MX, NS, TXT Records (Free CLI Tool)

Why DNS Record Checking Matters for Sysadmins

DNS (Domain Name System) is the backbone of the internet β€” it translates human-readable domain names into IP addresses. As a Linux sysadmin, you need to verify DNS records regularly: after domain migrations, email server changes, SSL certificate renewals, and DNS provider switches. Misconfigured DNS can cause website downtime, email delivery failures, and security vulnerabilities.

While tools like dig, nslookup, and host exist, they require memorizing different flags and parsing inconsistent output formats. dargslan-dns-check provides a unified, Pythonic interface for all DNS operations with clean JSON output and built-in propagation checking.

Install dargslan-dns-check

pip install dargslan-dns-check

Zero external dependencies β€” uses only the Python standard library. Works on any Linux distribution with Python 3.7+.

CLI Usage: Full DNS Report

The simplest way to get a complete DNS overview for any domain:

dargslan-dns example.com

This queries all common record types (A, AAAA, MX, NS, TXT, CNAME, SOA) and displays a formatted report with TTL values and priorities.

Query Specific Record Types

# MX records (mail servers)
dargslan-dns example.com -t MX

# Nameservers
dargslan-dns example.com -t NS

# TXT records (SPF, DKIM, DMARC)
dargslan-dns example.com -t TXT

# IPv6 addresses
dargslan-dns example.com -t AAAA

# SOA record (serial number, primary NS)
dargslan-dns example.com -t SOA

DNS Propagation Checking

After changing DNS records, propagation can take hours. Verify your changes have reached major DNS resolvers:

dargslan-dns example.com --propagation

This checks your domain against Google (8.8.8.8), Cloudflare (1.1.1.1), OpenDNS (208.67.222.222), and Quad9 (9.9.9.9) simultaneously.

Reverse DNS Lookup

dargslan-dns 8.8.8.8 --reverse

Perform PTR record lookups to find the hostname associated with an IP address β€” essential for email server verification and security investigations.

Python API for Automation

from dargslan_dns_check import DNSChecker

checker = DNSChecker()

# Query all record types
all_records = checker.query_all("example.com")
for rtype, records in all_records.items():
    print(f"{rtype}: {len(records)} records")

# Check specific type
mx_records = checker.query("example.com", "MX")
for mx in mx_records:
    print(f"Priority {mx.get('priority', '?')}: {mx['value']}")

# Propagation check
propagation = checker.check_propagation("example.com")
for result in propagation:
    print(f"{result['nameserver']}: {result['values']}")

# Reverse lookup
ptr = checker.reverse_lookup("1.1.1.1")
print(f"Hostname: {ptr['hostname']}")

JSON Output for Scripting

# CLI JSON output
dargslan-dns example.com --json

# Pipe to jq for filtering
dargslan-dns example.com --json | jq '.MX'

Use Cases

  • Domain migration: Verify all DNS records transferred correctly to new provider
  • Email troubleshooting: Check MX, SPF (TXT), DKIM, and DMARC records
  • SSL certificate renewal: Verify CNAME/TXT records for domain validation
  • Security audit: Check for dangling DNS entries and unauthorized records
  • Monitoring: Automate DNS record checks in Python scripts or cron jobs

Supported Record Types

TypeDescriptionCommon Use
AIPv4 AddressWebsite hosting
AAAAIPv6 AddressIPv6 hosting
MXMail ExchangeEmail routing
NSNameserverDNS delegation
TXTText RecordSPF, DKIM, verification
CNAMECanonical NameAliases, CDN
SOAStart of AuthorityZone serial, admin

Download the Free Cheat Sheet

Get the complete DNS Record Checker Cheat Sheet PDF with all CLI commands and Python API examples.

Related Tools from Dargslan

Explore our full collection of 20+ free Python CLI tools for Linux sysadmins, including SSL certificate checking, network scanning, firewall auditing, and more.

Looking to deepen your Linux and networking skills? Browse our 210+ eBooks on Linux administration, networking, and cybersecurity.

Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.