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.

There is currently no support for DNS-over-HTTPS using asynchronous I/O but we hope to offer this in the future.

UDP

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.

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.

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.

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

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.

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.

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

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.

Zone Transfers

dns.asyncquery.inbound_xfr(where, txn_manager, query=None, port=53, timeout=None, lifetime=None, source=None, source_port=0, udp_mode=<UDPMode.NEVER: 0>, 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.