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
resolvectlor/etc/resolv.conf), and macOS. - Wide Record Support: Supports
A,AAAA(IPv6),MX,TXT,NS,CNAME,SOA, andPTR. - Reverse DNS: Automatically handles reverse IP lookups when querying
PTRrecords. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lightweight_dns_resolver-0.1.0.tar.gz.
File metadata
- Download URL: lightweight_dns_resolver-0.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3217f10aa4104d11b6d0c4877d7f1596e9902126f1045124972b53e08aed18b
|
|
| MD5 |
6da145aa138f113046bad70028f8198a
|
|
| BLAKE2b-256 |
867d6e9492892fb8d3317c040fe5fffccc96503e8e98630bc0e5ea6fdf79042d
|
File details
Details for the file lightweight_dns_resolver-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lightweight_dns_resolver-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75ed3183e5ea7003c83176fc766839b1a346efe255dda1834ca3f8c099ef25a2
|
|
| MD5 |
65c50ccf6fdcad7ac38a22e44d87a974
|
|
| BLAKE2b-256 |
ca8b21c8d27181593026f292b421ebe4e2ae7816876ac4f17692b68a83e52144
|