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.
Initialize a resolver.
- Parameters:
filename (str or file) – A
stror file object specifying a file in standard/etc/resolv.confformat. Meaningful only when configure isTrueand the platform is POSIX.configure (bool) – If
True(the default), configure the resolver for the operating system (reads/etc/resolv.confon POSIX, registry on Windows).
- 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.
- Parameters:
name (
dns.name.Nameor str) – The query name.- Return type:
This method can raise any exception that
resolve()can raise, other thandns.resolver.NoAnsweranddns.resolver.NXDOMAIN.
- 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.
- Parameters:
backend (
dns.asyncbackend.BackendorNone) – The async backend. IfNone(the default), 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.
- Parameters:
ipaddr (str) – The IPv4 or IPv6 address to look up.
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.
- Parameters:
name (
dns.name.Nameor str) – The name to resolve.family (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.