Skip to main content

A pure Python DNS resolver supporting multiple record types

Project description

DNS Resolver

A robust, pure-Python DNS resolver built from scratch. This library allows you to perform DNS queries without relying on the OS's internal resolver or heavy external dependencies like dnspython.

It constructs raw DNS packets, sends them over UDP, and parses the binary response manually.

Features

  • Zero Dependencies: Runs on standard Python libraries (socket, struct, os, platform).
  • Cross-Platform: Automatically detects the system DNS server on Windows (via PowerShell), Linux (via resolvectl or /etc/resolv.conf), and macOS.
  • Wide Record Support: Supports A, AAAA (IPv6), MX, TXT, NS, CNAME, SOA, and PTR.
  • Reverse DNS: Automatically handles reverse IP lookups when querying PTR records.
  • Robust Parsing: Correctly handles DNS pointer compression.

Installation

pip install dns-resolver-yourname

Usage

Command Line Interface (CLI)

You can use the tool directly from your terminal after installation:

Basic Lookup (A Record)

dns-resolve google.com A

Get Mail Servers (MX)

**dns-resolve yahoo.com MX**

Reverse DNS (PTR) Simply enter the IP address, and the tool will format the query for you.

dns-resolve 8.8.8.8 PTR

Custom Server Query a specific DNS server (e.g., Cloudflare).

*dns-resolve google.com A --server 1.1.1.1

Python Library

You can also use it inside your own Python scripts:

from dns_resolver import resolve

# 1. Simple A Record lookup
# Returns a list of strings
results = resolve("example.com", "A")
for record in results:
    print(record)

# 2. Check for TXT records (useful for verification tokens)
txt_records = resolve("openai.com", "TXT")
print(txt_records)

# 3. Custom DNS Server
# Query 1.1.1.1 directly instead of the system default
resolve("google.com", "A", custom_server="1.1.1.1")

Supported Record Types

Type Description
A IPv4 Address
AAAA IPv6 Address
MX Mail Exchange
TXT Text strings (SPF, verification)
NS Name Server
CNAME Canonical Name (Alias)
SOA Start of Authority
PTR Pointer (Reverse DNS)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lightweight_dns_resolver-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lightweight_dns_resolver-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file lightweight_dns_resolver-0.1.0.tar.gz.

File metadata

File hashes

Hashes for lightweight_dns_resolver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b3217f10aa4104d11b6d0c4877d7f1596e9902126f1045124972b53e08aed18b
MD5 6da145aa138f113046bad70028f8198a
BLAKE2b-256 867d6e9492892fb8d3317c040fe5fffccc96503e8e98630bc0e5ea6fdf79042d

See more details on using hashes here.

File details

Details for the file lightweight_dns_resolver-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lightweight_dns_resolver-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75ed3183e5ea7003c83176fc766839b1a346efe255dda1834ca3f8c099ef25a2
MD5 65c50ccf6fdcad7ac38a22e44d87a974
BLAKE2b-256 ca8b21c8d27181593026f292b421ebe4e2ae7816876ac4f17692b68a83e52144

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page