DNS toolkit for Python supporting almost all record types with high-level and low-level DNS operations
85
Comprehensive constants and enumerations for DNS operations including record types, classes, flags, opcodes, and response codes. These constants are essential for working with DNS records and messages.
Constants defining all supported DNS record types. Used throughout dnspython for specifying record types in queries, messages, and data structures.
# Core record types
NONE = 0
A = 1
NS = 2
MD = 3
MF = 4
CNAME = 5
SOA = 6
MB = 7
MG = 8
MR = 9
NULL = 10
WKS = 11
PTR = 12
HINFO = 13
MINFO = 14
MX = 15
TXT = 16
RP = 17
AFSDB = 18
X25 = 19
ISDN = 20
RT = 21
NSAP = 22
NSAP_PTR = 23
SIG = 24
KEY = 25
PX = 26
GPOS = 27
AAAA = 28
LOC = 29
NXT = 30
EID = 31
NIMLOC = 32
SRV = 33
ATMA = 34
NAPTR = 35
KX = 36
CERT = 37
A6 = 38
DNAME = 39
SINK = 40
OPT = 41
APL = 42
DS = 43
SSHFP = 44
IPSECKEY = 45
RRSIG = 46
NSEC = 47
DNSKEY = 48
DHCID = 49
NSEC3 = 50
NSEC3PARAM = 51
TLSA = 52
HIP = 55
NINFO = 56
RKEY = 57
TALINK = 58
CDS = 59
CDNSKEY = 60
OPENPGPKEY = 61
CSYNC = 62
SPF = 99
UINFO = 100
UID = 101
GID = 102
UNSPEC = 103
NID = 104
L32 = 105
L64 = 106
LP = 107
EUI48 = 108
EUI64 = 109
TKEY = 249
TSIG = 250
IXFR = 251
AXFR = 252
MAILB = 253
MAILA = 254
ANY = 255
URI = 256
CAA = 257
AVC = 258
DOA = 259
AMTRELAY = 260
TA = 32768
DLV = 32769
def from_text(text: str) -> int
def to_text(value: int) -> str
def is_metatype(rdtype: int) -> bool
def is_singleton(rdtype: int) -> boolConstants defining DNS record classes for different network types and operational contexts.
RESERVED0 = 0
IN = 1 # Internet
CH = 3 # Chaos
HS = 4 # Hesiod
NONE = 254 # None (used in dynamic updates)
ANY = 255 # Any class (query wildcard)
def from_text(text: str) -> int
def to_text(value: int) -> str
def is_metaclass(rdclass: int) -> boolBit flag constants for DNS message headers controlling query behavior and response characteristics.
# Standard DNS header flags
QR = 0x8000 # Query Response (0=query, 1=response)
AA = 0x0400 # Authoritative Answer
TC = 0x0200 # Truncated Response
RD = 0x0100 # Recursion Desired
RA = 0x0080 # Recursion Available
Z = 0x0040 # Reserved (must be zero)
AD = 0x0020 # Authentic Data (DNSSEC)
CD = 0x0010 # Checking Disabled (DNSSEC)
def from_text(text: str) -> int
def to_text(value: int) -> strOperation codes defining the type of DNS operation being performed in a message.
QUERY = 0 # Standard query
IQUERY = 1 # Inverse query (deprecated)
STATUS = 2 # Server status request
NOTIFY = 4 # Zone change notification
UPDATE = 5 # Dynamic DNS update
def from_text(text: str) -> int
def to_text(value: int) -> strResponse codes indicating the result status of DNS operations and queries.
NOERROR = 0 # No error
FORMERR = 1 # Format error
SERVFAIL = 2 # Server failure
NXDOMAIN = 3 # Non-existent domain
NOTIMP = 4 # Not implemented
REFUSED = 5 # Query refused
YXDOMAIN = 6 # Name exists when it should not
YXRRSET = 7 # RR set exists when it should not
NXRRSET = 8 # RR set that should exist does not
NOTAUTH = 9 # Server not authoritative for zone
NOTZONE = 10 # Name not contained in zone
BADVERS = 16 # Bad OPT version
BADSIG = 16 # TSIG signature failure
BADKEY = 17 # Key not recognized
BADTIME = 18 # Signature out of time window
BADMODE = 19 # Bad TKEY mode
BADNAME = 20 # Duplicate key name
BADALG = 21 # Algorithm not supported
BADTRUNC = 22 # Bad truncation
def from_text(text: str) -> int
def to_text(value: int) -> strimport dns.rdatatype
# Convert between text and numeric forms
a_type = dns.rdatatype.from_text('A') # Returns 1
type_name = dns.rdatatype.to_text(1) # Returns 'A'
# Check record type properties
is_meta = dns.rdatatype.is_metatype(dns.rdatatype.ANY) # True
is_single = dns.rdatatype.is_singleton(dns.rdatatype.SOA) # True
# Use constants directly
query_type = dns.rdatatype.AAAA # IPv6 address record
mx_type = dns.rdatatype.MX # Mail exchange recordimport dns.flags
# Combine flags for query messages
flags = dns.flags.RD | dns.flags.AD # Recursion desired + authentic data
# Check individual flags
if response_flags & dns.flags.AA:
print("Response is authoritative")
if response_flags & dns.flags.TC:
print("Response was truncated, retry with TCP")import dns.rcode
# Check response status
if response.rcode() == dns.rcode.NOERROR:
print("Query successful")
elif response.rcode() == dns.rcode.NXDOMAIN:
print("Domain does not exist")
elif response.rcode() == dns.rcode.SERVFAIL:
print("Server failure")
# Convert response codes to text
error_text = dns.rcode.to_text(response.rcode())# All constants modules provide these utility functions
def from_text(text: str) -> int:
"""Convert text name to numeric value."""
def to_text(value: int) -> str:
"""Convert numeric value to text name."""
# Record type specific functions
def is_metatype(rdtype: int) -> bool:
"""Check if record type is a metatype (like ANY)."""
def is_singleton(rdtype: int) -> bool:
"""Check if only one record of this type can exist per name."""
# Record class specific functions
def is_metaclass(rdclass: int) -> bool:
"""Check if record class is a metaclass (like ANY)."""Install with Tessl CLI
npx tessl i tessl/pypi-dnspythondocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10