Resolver Functions and The Default Resolver
- dns.resolver.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) Answer [source]
Query nameservers to find the answer to the question.
This is a convenience function that uses the default resolver object to make the query.
See
dns.resolver.Resolver.resolve
for more information on the parameters.
- dns.resolver.resolve_address(ipaddr: str, *args: Any, **kwargs: Any) Answer [source]
Use a resolver to run a reverse query for PTR records.
See
dns.resolver.Resolver.resolve_address
for more information on the parameters.
- dns.resolver.resolve_name(name: Name | str, family: int = AddressFamily.AF_UNSPEC, **kwargs: Any) HostAnswers [source]
Use a resolver to query for address records.
See
dns.resolver.Resolver.resolve_name
for more information on the parameters.
- dns.resolver.canonical_name(name: Name | str) Name [source]
Determine the canonical name of name.
See
dns.resolver.Resolver.canonical_name
for more information on the parameters and possible exceptions.
- dns.resolver.try_ddr(lifetime: float = 5.0) None [source]
Try to update the default 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.
See
dns.resolver.Resolver.try_ddr()
for more information.
- dns.resolver.zone_for_name(name: Name | str, rdclass: RdataClass = RdataClass.IN, tcp: bool = False, resolver: Resolver | None = None, lifetime: float | None = None) Name [source]
Find the name of the zone which contains the specified name.
name, an absolute
dns.name.Name
orstr
, the query name.rdclass, an
int
, the query class.tcp, a
bool
. IfTrue
, use TCP to make the query.resolver, a
dns.resolver.Resolver
orNone
, the resolver to use. IfNone
, the default, then the default resolver is used.lifetime, a
float
, the total time to allow for the queries needed to determine the zone. IfNone
, the default, then only the individual query limits of the resolver apply.Raises
dns.resolver.NoRootSOA
if there is no SOA RR at the DNS root. (This is only likely to happen if you’re using non-default root servers in your network and they are misconfigured.)Raises
dns.resolver.LifetimeTimeout
if the answer could not be found in the allotted lifetime.Returns a
dns.name.Name
.
- dns.resolver.query(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) Answer [source]
Query nameservers to find the answer to the question.
This method calls resolve() with
search=True
, and is provided for backwards compatibility with prior versions of dnspython. See the documentation for the resolve() method for further details.
- dns.resolver.make_resolver_at(where: Name | str, port: int = 53, family: int = AddressFamily.AF_UNSPEC, resolver: Resolver | None = None) Resolver [source]
Make a stub resolver using the specified destination as the full resolver.
where, a
dns.name.Name
orstr
the domain name or IP address of the full resolver.port, an
int
, the port to use. If not specified, the default is 53.family, an
int
, the address family to use. This parameter is used if where is not an address. The default issocket.AF_UNSPEC
in which case the first address returned byresolve_name()
will be used, otherwise the first address of the specified family will be used.resolver, a
dns.resolver.Resolver
orNone
, the resolver to use for resolution of hostnames. If not specified, the default resolver will be used.Returns a
dns.resolver.Resolver
or raises an exception.
- dns.resolver.resolve_at(where: Name | str, 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, port: int = 53, family: int = AddressFamily.AF_UNSPEC, resolver: Resolver | None = None) Answer [source]
Query nameservers to find the answer to the question.
This is a convenience function that calls
dns.resolver.make_resolver_at()
to make a resolver, and then uses it to resolve the query.See
dns.resolver.Resolver.resolve
for more information on the resolution parameters, anddns.resolver.make_resolver_at
for information about the resolver parameters where, port, family, and resolver.If making more than one query, it is more efficient to call
dns.resolver.make_resolver_at()
and then use that resolver for the queries instead of callingresolve_at()
multiple times.