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.resolvefor 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_addressfor 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_namefor 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_namefor 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.
- Parameters:
name (
dns.name.Nameor str) – An absolute query name.rdclass (
dns.rdataclass.RdataClass) – The query class.tcp (bool) – If
True, use TCP to make the query.resolver (
dns.resolver.ResolverorNone) – The resolver to use. IfNone, the default resolver is used.lifetime (float or
None) – Total time to allow for the queries. IfNone, only the individual query limits of the resolver apply.
- Raises:
dns.resolver.NoRootSOA – If there is no SOA RR at the DNS root.
dns.resolver.LifetimeTimeout – If the answer could not be found within the allotted lifetime.
- Return type:
- 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 thedns.resolver.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.
- Parameters:
where (
dns.name.Nameor str) – The domain name or IP address of the full resolver.port (int) – The port to use. Default is 53.
family (int) – The address family. Used only when where is not an address literal.
socket.AF_UNSPEC(default) uses the first address returned; otherwise the first address of the given family.resolver (
dns.resolver.ResolverorNone) – The resolver to use for hostname resolution. IfNone, the default resolver is used.
- Return type:
- 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.resolvefor more information on the resolution parameters, anddns.resolver.make_resolver_atfor 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.