server (version 1.0.0)
index
server.py

Async DNS server.
 
- UDP + TCP listeners (both on same host:port)
Zone configuration loaded from JSON
- Pluggable resolver callback
- Transport-agnostic: uses dns_codec for all packet work

 
Classes
       
builtins.object
DNSRequestHandler
DNSServer
Zone

 
class DNSRequestHandler(builtins.object)
    DNSRequestHandler(
    zone: Optional[Zone] = None,
    resolver: Optional[ResolverCallback] = None
)
 
Handles DNS request/response logic.
Completely decoupled from transport (UDP/TCP).
 
Priority:
  1. Custom resolver callback (if set)
  2. Zone lookup
  3. NXDOMAIN
 
  Methods defined here:
__init__( self, zone: Optional[Zone] = None, resolver: Optional[ResolverCallback] = None )
Initialize self.  See help(type(self)) for accurate signature.
handle(self, raw: bytes) -> Optional[bytes]
Takes raw DNS query bytes.
Returns raw DNS response bytes, or None if the packet is invalid.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class DNSServer(builtins.object)
    DNSServer(
    zone: Optional[Zone] = None,
    resolver: Optional[ResolverCallback] = None,
    host: str = '0.0.0.0',
    port: int = 5353
)
 
Async DNS server binding both UDP and TCP on the same host:port.
 
Usage:
    zone = Zone.from_json("zone.json")
    server = DNSServer(zone=zone, host="0.0.0.0", port=5353)
    await server.start()
 
  Methods defined here:
__init__( self, zone: Optional[Zone] = None, resolver: Optional[ResolverCallback] = None, host: str = '0.0.0.0', port: int = 5353 )
Initialize self.  See help(type(self)) for accurate signature.
close(self) -> None
Close the UDP transport and TCP server.
async serve_forever(self) -> None
Start the server and serve requests indefinitely.
 
This method blocks until the server is stopped.
async start(self) -> None
Start the DNS server.
 
Initializes both UDP and TCP endpoints on the configured host and port.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Zone(builtins.object)
    Zone(ttl: int = 300)
 
Represents an in-memory DNS zone storing resource records indexed by (name, type).
 
  Methods defined here:
__init__(self, ttl: int = 300)
Initialize self.  See help(type(self)) for accurate signature.
add(self, name: str, rtype: int, rdata: Any, ttl: Optional[int] = None)
Add a DNS record to the zone.
 
Args:
    name: Domain name.
    rtype: DNS record type.
    rdata: Record data (raw or structured).
    ttl: Optional time-to-live; defaults to zone TTL.
lookup(self, name: str, qtype: int) -> List[DNSResourceRecord]
Lookup DNS records by name and type.
 
Returns all matching records, or all types if qtype is ANY.

Class methods defined here:
from_dict(data: dict, ttl: int = 300) -> Zone
Build a Zone from a dictionary structure.
 
The input dictionary maps domain names to record definitions.
 
Args:
    data: Dictionary containing DNS records.
    ttl: Default TTL applied when not specified.
 
Returns:
    A populated Zone instance.
from_json(path: str, ttl: int = 300) -> Zone
Load a Zone from a JSON file.
 
Args:
    path: Path to the JSON file.
    ttl: Default TTL applied when not specified.
 
Returns:
    A populated Zone instance.
from_json_string(json_str: str, ttl: int = 300) -> Zone
Build a Zone from a JSON string.
 
Args:
    json_str: JSON string containing DNS records.
    ttl: Default TTL applied when not specified.
 
Returns:
    A populated Zone instance.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
Functions
       
async start_dns_server( host: str = '0.0.0.0', port: int = 5353, zone: Optional[Zone] = None, resolver: Optional[ResolverCallback] = None ) -> DNSServer
Convenience function to start and return a running DNSServer.

 
Data
        __all__ = ['Zone', 'DNSRequestHandler', 'DNSServer', 'start_dns_server']
__author_email__ = 'mauricelambert434@gmail.com'
__copyright__ = '\nPyAsyncDNS Copyright (C) 2025, 2026 Maurice L...ome to redistribute it\nunder certain conditions.\n'
__description__ = '\nThis package implements a basic asynchronous DN...r\nwith a feature to exfiltrate data through DNS.\n'
__license__ = 'GPL-3.0 License'
__maintainer__ = 'Maurice Lambert'
__maintainer_email__ = 'mauricelambert434@gmail.com'
__url__ = 'https://github.com/mauricelambert/PyAsyncDNS'

 
Author
        Maurice Lambert