Name Helpers

Sometimes you want to look up an address in the DNS instead of a name. Dnspython provides a helper functions for converting between addresses and their “reverse map” form in the DNS.

For example:

Address

DNS Reverse Name

127.0.0.1

1.0.0.127.in-addr.arpa.

::1

1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.


dns.reversename.from_address(text: str, v4_origin: ~dns.name.Name = <DNS name in-addr.arpa.>, v6_origin: ~dns.name.Name = <DNS name ip6.arpa.>) Name[source]

Convert an IPv4 or IPv6 address in textual form into a Name object whose value is the reverse-map domain name of the address.

text, a str, is an IPv4 or IPv6 address in textual form (e.g. ‘127.0.0.1’, ‘::1’)

v4_origin, a dns.name.Name to append to the labels corresponding to the address if the address is an IPv4 address, instead of the default (in-addr.arpa.)

v6_origin, a dns.name.Name to append to the labels corresponding to the address if the address is an IPv6 address, instead of the default (ip6.arpa.)

Raises dns.exception.SyntaxError if the address is badly formed.

Returns a dns.name.Name.

dns.reversename.to_address(name: ~dns.name.Name, v4_origin: ~dns.name.Name = <DNS name in-addr.arpa.>, v6_origin: ~dns.name.Name = <DNS name ip6.arpa.>) str[source]

Convert a reverse map domain name into textual address form.

name, a dns.name.Name, an IPv4 or IPv6 address in reverse-map name form.

v4_origin, a dns.name.Name representing the top-level domain for IPv4 addresses, instead of the default (in-addr.arpa.)

v6_origin, a dns.name.Name representing the top-level domain for IPv4 addresses, instead of the default (ip6.arpa.)

Raises dns.exception.SyntaxError if the name does not have a reverse-map form.

Returns a str.

Dnspython also provides helpers for converting E.164 numbers (i.e. telephone numbers) into the names used for them in the DNS.

For example:

Number

DNS E.164 Name

+1.650.555.1212

2.1.2.1.5.5.5.0.5.6.1.e164.arpa.

+44 20 7946 0123

3.2.1.0.6.4.9.7.0.2.4.4.e164.arpa.


dns.e164.from_e164(text: str, origin: ~dns.name.Name | None = <DNS name e164.arpa.>) Name[source]

Convert an E.164 number in textual form into a Name object whose value is the ENUM domain name for that number.

Non-digits in the text are ignored, i.e. “16505551212”, “+1.650.555.1212” and “1 (650) 555-1212” are all the same.

text, a str, is an E.164 number in textual form.

origin, a dns.name.Name, the domain in which the number should be constructed. The default is e164.arpa..

Returns a dns.name.Name.

dns.e164.to_e164(name: ~dns.name.Name, origin: ~dns.name.Name | None = <DNS name e164.arpa.>, want_plus_prefix: bool = True) str[source]

Convert an ENUM domain name into an E.164 number.

Note that dnspython does not have any information about preferred number formats within national numbering plans, so all numbers are emitted as a simple string of digits, prefixed by a ‘+’ (unless want_plus_prefix is False).

name is a dns.name.Name, the ENUM domain name.

origin is a dns.name.Name, a domain containing the ENUM domain name. The name is relativized to this domain before being converted to text. If None, no relativization is done.

want_plus_prefix is a bool. If True, add a ‘+’ to the beginning of the returned number.

Returns a str.