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: Name = <DNS name in-addr.arpa.>, v6_origin: 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.
- Parameters:
text (str) – An IPv4 or IPv6 address in textual form (e.g.
'127.0.0.1','::1').v4_origin (
dns.name.Name) – Domain to append for IPv4 addresses instead ofin-addr.arpa.v6_origin (
dns.name.Name) – Domain to append for IPv6 addresses instead ofip6.arpa.
- Raises:
dns.exception.SyntaxError – If the address is badly formed.
- Return type:
- dns.reversename.to_address(name: Name, v4_origin: Name = <DNS name in-addr.arpa.>, v6_origin: Name = <DNS name ip6.arpa.>) str[source]
Convert a reverse map domain name into textual address form.
- Parameters:
name (
dns.name.Name) – An IPv4 or IPv6 address in reverse-map name form.v4_origin (
dns.name.Name) – Top-level domain for IPv4 addresses (defaultin-addr.arpa.).v6_origin (
dns.name.Name) – Top-level domain for IPv6 addresses (defaultip6.arpa.).
- Raises:
dns.exception.SyntaxError – If the name does not have a reverse-map form.
- Return type:
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: 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.
- Parameters:
text (str) – An E.164 number in textual form.
origin (
dns.name.Name) – The domain in which the number should be constructed. Default ise164.arpa.
- Return type:
- dns.e164.to_e164(name: Name, origin: 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).- Parameters:
name (
dns.name.Name) – The ENUM domain name.origin (
dns.name.NameorNone) – A domain containing the ENUM domain name. The name is relativized to this domain before conversion. IfNone, no relativization is done.want_plus_prefix (bool) – If
True, add a'+'prefix to the returned number.
- Return type: