DNS Query Support

The dns.asyncquery module is for sending messages to DNS servers, and processing their responses. If you want “stub resolver” behavior, then you should use the higher level dns.asyncresolver module; see Stub Resolver.

For UDP and TCP, the module provides a single “do everything” query function, and also provides the send and receive halves of this function individually for situations where more sophisticated I/O handling is being used by the application.

UDP

async dns.asyncquery.udp(q, where, timeout=None, port=53, source=None, source_port=0, ignore_unexpected=False, one_rr_per_rrset=False, ignore_trailing=False, raise_on_truncation=False, sock=None, backend=None)[source]

Return the response obtained after sending a query via UDP.

sock, a dns.asyncbackend.DatagramSocket, or None, the socket to use for the query. If None, the default, a socket is created. Note that if a socket is provided, the source, source_port, and backend are ignored.

backend, a dns.asyncbackend.Backend, or None. If None, the default, then dnspython will use the default backend.

See dns.query.udp() for the documentation of the other parameters, exceptions, and return type of this method.

async dns.asyncquery.udp_with_fallback(q, where, timeout=None, port=53, source=None, source_port=0, ignore_unexpected=False, one_rr_per_rrset=False, ignore_trailing=False, udp_sock=None, tcp_sock=None, backend=None)[source]

Return the response to the query, trying UDP first and falling back to TCP if UDP results in a truncated response.

udp_sock, a dns.asyncbackend.DatagramSocket, or None, the socket to use for the UDP query. If None, the default, a socket is created. Note that if a socket is provided the source, source_port, and backend are ignored for the UDP query.

tcp_sock, a dns.asyncbackend.StreamSocket, or None, the socket to use for the TCP query. If None, the default, a socket is created. Note that if a socket is provided where, source, source_port, and backend are ignored for the TCP query.

backend, a dns.asyncbackend.Backend, or None. If None, the default, then dnspython will use the default backend.

See dns.query.udp_with_fallback() for the documentation of the other parameters, exceptions, and return type of this method.

async dns.asyncquery.send_udp(sock, what, destination, expiration=None)[source]

Send a DNS message to the specified UDP socket.

sock, a dns.asyncbackend.DatagramSocket.

what, a bytes or dns.message.Message, the message to send.

destination, a destination tuple appropriate for the address family of the socket, specifying where to send the query.

expiration, a float or None, the absolute time at which a timeout exception should be raised. If None, no timeout will occur.

Returns an (int, float) tuple of bytes sent and the sent time.

async dns.asyncquery.receive_udp(sock, destination=None, expiration=None, ignore_unexpected=False, one_rr_per_rrset=False, keyring=None, request_mac=b'', ignore_trailing=False, raise_on_truncation=False)[source]

Read a DNS message from a UDP socket.

sock, a dns.asyncbackend.DatagramSocket.

See dns.query.receive_udp() for the documentation of the other parameters, exceptions, and return type of this method.

TCP

async dns.asyncquery.tcp(q, where, timeout=None, port=53, source=None, source_port=0, one_rr_per_rrset=False, ignore_trailing=False, sock=None, backend=None)[source]

Return the response obtained after sending a query via TCP.

sock, a dns.asyncbacket.StreamSocket, or None, the socket to use for the query. If None, the default, a socket is created. Note that if a socket is provided where, port, source, source_port, and backend are ignored.

backend, a dns.asyncbackend.Backend, or None. If None, the default, then dnspython will use the default backend.

See dns.query.tcp() for the documentation of the other parameters, exceptions, and return type of this method.

async dns.asyncquery.send_tcp(sock, what, expiration=None)[source]

Send a DNS message to the specified TCP socket.

sock, a dns.asyncbackend.StreamSocket.

See dns.query.send_tcp() for the documentation of the other parameters, exceptions, and return type of this method.

async dns.asyncquery.receive_tcp(sock, expiration=None, one_rr_per_rrset=False, keyring=None, request_mac=b'', ignore_trailing=False)[source]

Read a DNS message from a TCP socket.

sock, a dns.asyncbackend.StreamSocket.

See dns.query.receive_tcp() for the documentation of the other parameters, exceptions, and return type of this method.

TLS

async dns.asyncquery.tls(q, where, timeout=None, port=853, source=None, source_port=0, one_rr_per_rrset=False, ignore_trailing=False, sock=None, backend=None, ssl_context=None, server_hostname=None)[source]

Return the response obtained after sending a query via TLS.

sock, an asyncbackend.StreamSocket, or None, the socket to use for the query. If None, the default, a socket is created. Note that if a socket is provided, it must be a connected SSL stream socket, and where, port, source, source_port, backend, ssl_context, and server_hostname are ignored.

backend, a dns.asyncbackend.Backend, or None. If None, the default, then dnspython will use the default backend.

See dns.query.tls() for the documentation of the other parameters, exceptions, and return type of this method.

HTTPS

async dns.asyncquery.https(q, where, timeout=None, port=443, source=None, source_port=0, one_rr_per_rrset=False, ignore_trailing=False, client=None, path='/dns-query', post=True, verify=True)[source]

Return the response obtained after sending a query via DNS-over-HTTPS.

client, a httpx.AsyncClient. If provided, the client to use for the query.

Unlike the other dnspython async functions, a backend cannot be provided in this function because httpx always auto-detects the async backend.

See dns.query.https() for the documentation of the other parameters, exceptions, and return type of this method.

Zone Transfers

async dns.asyncquery.inbound_xfr(where, txn_manager, query=None, port=53, timeout=None, lifetime=None, source=None, source_port=0, udp_mode=UDPMode.NEVER, backend=None)[source]

Conduct an inbound transfer and apply it via a transaction from the txn_manager.

backend, a dns.asyncbackend.Backend, or None. If None, the default, then dnspython will use the default backend.

See dns.query.inbound_xfr() for the documentation of the other parameters, exceptions, and return type of this method.