The dns.asyncresolver.Resolver Class

The async resolver is a subclass of dns.resolver.Resolver and has the same attributes. The methods are similar, but I/O methods like resolve() are asynchronous.

class dns.asyncresolver.Resolver(filename: str = '/etc/resolv.conf', configure: bool = True)[source]

Asynchronous DNS stub resolver.

filename, a str or file object, specifying a file in standard /etc/resolv.conf format. This parameter is meaningful only when configure is true and the platform is POSIX.

configure, a bool. If True (the default), the resolver instance is configured in the normal fashion for the operating system the resolver is running on. (I.e. by reading a /etc/resolv.conf file on POSIX systems and from the registry on Windows systems.)

async canonical_name(name: Name | str) Name[source]

Determine the canonical name of name.

The canonical name is the name the resolver uses for queries after all CNAME and DNAME renamings have been applied.

name, a dns.name.Name or str, the query name.

This method can raise any exception that resolve() can raise, other than dns.resolver.NoAnswer and dns.resolver.NXDOMAIN.

Returns a dns.name.Name.

async resolve(qname: Name | str, rdtype: RdataType | str = RdataType.A, rdclass: RdataClass | str = RdataClass.IN, tcp: bool = False, source: str | None = None, raise_on_no_answer: bool = True, source_port: int = 0, lifetime: float | None = None, search: bool | None = None, backend: Backend | None = None) Answer[source]

Query nameservers asynchronously to find the answer to the question.

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

See dns.resolver.Resolver.resolve() for the documentation of the other parameters, exceptions, and return type of this method.

async resolve_address(ipaddr: str, *args: Any, **kwargs: Any) Answer[source]

Use an asynchronous resolver to run a reverse query for PTR records.

This utilizes the resolve() method to perform a PTR lookup on the specified IP address.

ipaddr, a str, the IPv4 or IPv6 address you want to get the PTR record for.

All other arguments that can be passed to the resolve() function except for rdtype and rdclass are also supported by this function.

async resolve_name(name: Name | str, family: int = AddressFamily.AF_UNSPEC, **kwargs: Any) HostAnswers[source]

Use an asynchronous resolver to query for address records.

This utilizes the resolve() method to perform A and/or AAAA lookups on the specified name.

qname, a dns.name.Name or str, the name to resolve.

family, an int, the address family. If socket.AF_UNSPEC (the default), both A and AAAA records will be retrieved.

All other arguments that can be passed to the resolve() function except for rdtype and rdclass are also supported by this function.

async try_ddr(lifetime: float = 5.0) None[source]

Try to update the resolver’s nameservers using Discovery of Designated Resolvers (DDR). If successful, the resolver will subsequently use DNS-over-HTTPS or DNS-over-TLS for future queries.

lifetime, a float, is the maximum time to spend attempting DDR. The default is 5 seconds.

If the SVCB query is successful and results in a non-empty list of nameservers, then the resolver’s nameservers are set to the returned servers in priority order.

The current implementation does not use any address hints from the SVCB record, nor does it resolve addresses for the SCVB target name, rather it assumes that the bootstrap nameserver will always be one of the addresses and uses it. A future revision to the code may offer fuller support. The code verifies that the bootstrap nameserver is in the Subject Alternative Name field of the TLS certficate.