]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
add reversemap module
authorBob Halley <halley@dnspython.org>
Mon, 26 Dec 2005 01:39:53 +0000 (01:39 +0000)
committerBob Halley <halley@dnspython.org>
Mon, 26 Dec 2005 01:39:53 +0000 (01:39 +0000)
dns/__init__.py
dns/reversemap.py [new file with mode: 0644]

index f14e06a1a10cdd4bf4d6822ecb976ddaa4836a7b..2b888242cf99f4922931c81b316858ee22361d8f 100644 (file)
@@ -35,6 +35,7 @@ __all__ = [
     'rdatatype',
     'renderer',
     'resolver',
+    'reversemap',
     'rrset',
     'set',
     'tokenizer',
diff --git a/dns/reversemap.py b/dns/reversemap.py
new file mode 100644 (file)
index 0000000..2a4998f
--- /dev/null
@@ -0,0 +1,39 @@
+# Copyright (C) 2005 Nominum, Inc.
+#
+# Permission to use, copy, modify, and distribute this software and its
+# documentation for any purpose with or without fee is hereby granted,
+# provided that the above copyright notice and this permission notice
+# appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+"""DNS Reverse Map Names."""
+
+import dns.name
+import dns.ipv6
+import dns.ipv4
+
+def from_text(text):
+    """Convert an IPv4 or IPv6 address in textual form into a Name object whose
+    value is the reverse-map domain name of the address.
+    @param text: an IPv4 or IPv6 address in textual form (e.g. '127.0.0.1',
+    '::1')
+    @type text: str
+    @rtype: dns.name.Name object
+    """
+    
+    try:
+        parts = list(dns.ipv6.inet_aton(text).encode('hex_codec'))
+        suffix = 'ip6.arpa.'
+    except:
+        parts = ['%d' % ord(byte) for byte in dns.ipv4.inet_aton(text)]
+        suffix = 'in-addr.arpa.'
+    parts.reverse()
+    parts.append(suffix)
+    return dns.name.from_text('.'.join(parts))