Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(133599)

Unified Diff: Lib/ipaddress.py

Issue 20480: Add ipaddress property to get reverse DNS name
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Doc/library/ipaddress.rst ('k') | Lib/test/test_ipaddress.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
index 97ff13d..7c1abca 100644
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -436,6 +436,17 @@ class _IPAddressBase(_TotalOrderingMixin):
return str(self)
@property
+ def reverse_pointer(self):
+ """The name of the reverse DNS pointer for the IP address, e.g.:
+ >>> ipaddress.ip_address("127.0.0.1").reverse_pointer
+ '1.0.0.127.in-addr.arpa'
+ >>> ipaddress.ip_address("2001:db8::1").reverse_pointer
+ '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
+
+ """
+ return self._reverse_pointer()
+
+ @property
def version(self):
msg = '%200s has no version specified' % (type(self),)
raise NotImplementedError(msg)
@@ -1166,6 +1177,15 @@ class _BaseV4:
return True
return False
+ def _reverse_pointer(self):
+ """Return the reverse DNS pointer name for the IPv4 address.
+
+ This implements the method described in RFC1035 3.5.
+
+ """
+ reverse_octets = str(self).split('.')[::-1]
+ return '.'.join(reverse_octets) + '.in-addr.arpa'
+
@property
def max_prefixlen(self):
return self._max_prefixlen
@@ -1746,6 +1766,15 @@ class _BaseV6:
return '%s/%d' % (':'.join(parts), self._prefixlen)
return ':'.join(parts)
+ def _reverse_pointer(self):
+ """Return the reverse DNS pointer name for the IPv6 address.
+
+ This implements the method described in RFC3596 2.5.
+
+ """
+ reverse_chars = self.exploded[::-1].replace(':', '')
+ return '.'.join(reverse_chars) + '.ip6.arpa'
+
@property
def max_prefixlen(self):
return self._max_prefixlen
« no previous file with comments | « Doc/library/ipaddress.rst ('k') | Lib/test/test_ipaddress.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+