dns

DNS module.

class spicerack.dns.Dns(*, nameserver_address: Optional[str] = None, port: Optional[int] = None)[source]

Class to interact with the DNS.

Initialize the instance.

Parameters
  • nameserver_address (str, optional) -- the nameserver address to use, if not set uses the OS configuration.

  • port (int, optional) -- the port the nameserver_address nameserver is listening to, if different from the default 53. This applies only if a nameserver is explicitely specified.

resolve(qname: Union[str, dns.name.Name], record_type: str) → dns.resolver.Answer[source]

Perform a DNS lookup for the given qname and record type.

Parameters
  • qname (str) -- the name or address to resolve.

  • record_type (str) -- the DNS record type to lookup for, like 'A', 'AAAA', 'PTR', etc.

Returns

the DNS response.

Return type

dns.resolver.Answer

Raises
resolve_cname(name: str)str[source]

Perform a DNS lookup for CNAME record for the given name.

Parameters

name (str) -- the name to resolve.

Returns

the absolute target name for this CNAME, without the trailing dot.

Return type

str

resolve_ips(name: str) → List[str][source]

Perform a DNS lookup for A and AAAA records for the given name.

Parameters

name (str) -- the name to resolve.

Returns

the list of IPv4 and IPv6 addresses as strings returned by the DNS response.

Return type

list

Raises

spicerack.dns.DnsNotFound -- when no address is found.

resolve_ipv4(name: str) → List[str][source]

Perform a DNS lookup for an A record for the given name.

Parameters

name (str) -- the name to resolve.

Returns

the list of IPv4 addresses as strings returned by the DNS response.

Return type

list

resolve_ipv6(name: str) → List[str][source]

Perform a DNS lookup for an AAAA record for the given name.

Parameters

name (str) -- the name to resolve.

Returns

the list of IPv6 addresses as strings returned by the DNS response.

Return type

list

resolve_ptr(address: str) → List[str][source]

Perform a DNS lookup for PTR record for the given address.

Parameters

address (str) -- the IPv4 or IPv6 address to resolve.

Returns

the list of absolute target PTR records as strings, without the trailing dot.

Return type

list

exception spicerack.dns.DnsError[source]

Custom exception class for errors of the Dns class.

exception spicerack.dns.DnsNotFound[source]

Custom exception class to indicate the record was not found.

One or more resource records exist for this domain but there isn’t a record matching the resource record type.