3.8. lars.dns - DNS Resolution¶
This module provides a couple of trivial DNS resolution functions, enhanced
with LRU caches. Most users should never need to access these functions
directly. Instead, use the address
and
hostname
properties of relevant objects.
3.8.1. Functions¶
-
lars.dns.
from_address
(address)[source]¶ Reverse resolve an address to a hostname.
Given a string containing an IPv4 or IPv6 address, this functions returns a hostname associated with the address, using an LRU cache to speed up repeat queries. If the address does not reverse, the function returns the original address.
Parameters: address (str) – The address to resolve to a hostname Returns: The resolved hostname
-
lars.dns.
to_address
(hostname, family=<AddressFamily.AF_UNSPEC: 0>, socktype=<SocketKind.SOCK_STREAM: 1>)[source]¶ Resolve a hostname to an address, preferring IPv4 addresses.
Given a string containing a DNS hostname, this function resolves the hostname to an address, using an LRU cache to speed up repeat queries. The function prefers IPv4 addresses, but will return IPv6 addresses if no IPv4 addresses are present in the result from getaddrinfo. If the hostname does not resolve, the function returns None rather than raise an exception (this is preferable as it provides a negative lookup cache).
Parameters: hostname (str) – The hostname to resolve to an address Returns: The resolved address