|
From: David T. <db...@us...> - 2002-05-08 15:08:04
|
Update of /cvsroot/pydns/pydns/DNS
In directory usw-pr-cvs1:/tmp/cvs-serv19212/DNS
Modified Files:
Lib.py lazy.py
Log Message:
AAAA records and ip6.int/ip6.arpa reverse.
Index: Lib.py
===================================================================
RCS file: /cvsroot/pydns/pydns/DNS/Lib.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Lib.py 19 Mar 2002 13:05:02 -0000 1.11
--- Lib.py 8 May 2002 15:05:34 -0000 1.12
***************
*** 46,49 ****
--- 46,52 ----
return struct_pack('!L', n)
+ def pack128bit(n):
+ return struct_pack('!4I', n)
+
def unpack16bit(s):
return struct_unpack('!H', s)[0]
***************
*** 52,55 ****
--- 55,62 ----
return struct_unpack('!L', s)[0]
+ def unpack128bit(s):
+ # unlike the other unpack functions, this one keeps the tuple as a tuple
+ return struct_unpack('!4I', s)
+
def addr2bin(addr):
if type(addr) == type(0): return addr
***************
*** 65,68 ****
--- 72,129 ----
+ def bin2addr6(t):
+ comp = 0 # 0 - no compression yet, 1 - compressing, 2 - already compressed
+ mask = (0xffff0000,0xffff)
+ shift = (16, 0)
+ ret = ''
+ for n in 0,1,2,3:
+ for sub in 0,1:
+ if comp < 2 and ((t[n] & mask[sub])==0):
+ # and skip it
+ comp = 1
+ else:
+ if(comp==1):
+ comp=2
+ ret += ':'
+ if(ret):
+ ret += ':'
+ ret += '%x' %(((t[n] & mask[sub]) >> shift[sub]) & 0xffff)
+ return(ret)
+
+ def addr62bin(s):
+ if s[:2] == '::':
+ s = '0' + p
+ elif s[:1] == ':':
+ raise ValueError, 'bad IPv6 address'
+
+ parts = s.split(':')
+ if len(parts)>8:
+ raise ValueError, 'bad IPv6 address'
+ elif len(parts) == 8:
+ pass
+ else:
+ m = 9 - len(parts)
+ parts = s.split('::')
+ if not len(parts) == 2:
+ raise ValueError, 'bad IPv6 address'
+ s = parts[0] + ':'
+ for n in range(0,m):
+ s += '0:'
+ s += parts[1]
+ parts = s.split(':')
+ for word in parts:
+ try:
+ i = int(word,16)
+ if i > 65535 or i < 0:
+ raise ValueError, 'bad IPv6 address'
+ except:
+ raise ValueError, 'bad IPv6 address'
+
+ t = ((int(parts[0],16) << 16) + int(parts[1],16), \
+ (int(parts[2],16) << 16) + int(parts[3],16), \
+ (int(parts[4],16) << 16) + int(parts[5],16), \
+ (int(parts[6],16) << 16) + int(parts[7],16))
+ return(t)
+
# Packing class
***************
*** 180,185 ****
--- 241,250 ----
def get32bit(self):
return unpack32bit(self.getbytes(4))
+ def get128bit(self):
+ return unpack128bit(self.getbytes(16))
def getaddr(self):
return bin2addr(self.get32bit())
+ def getaddr6(self):
+ return bin2addr6(self.get128bit())
def getstring(self):
return self.getbytes(ord(self.getbyte()))
***************
*** 408,411 ****
--- 473,478 ----
def getAdata(self):
return self.getaddr()
+ def getAAAAdata(self):
+ return self.getaddr6()
def getWKSdata(self):
address = self.getaddr()
***************
*** 632,635 ****
--- 699,705 ----
#
# $Log$
+ # Revision 1.12 2002/05/08 15:05:34 dbt
+ # AAAA records and ip6.int/ip6.arpa reverse.
+ #
# Revision 1.11 2002/03/19 13:05:02 anthonybaxter
# converted to class based exceptions (there goes the python1.4 compatibility :)
Index: lazy.py
===================================================================
RCS file: /cvsroot/pydns/pydns/DNS/lazy.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** lazy.py 6 May 2002 06:14:38 -0000 1.5
--- lazy.py 8 May 2002 15:05:34 -0000 1.6
***************
*** 9,14 ****
--- 9,17 ----
# routines for lazy people.
import Base
+ import Lib
+
import string
+
def revlookup(name):
"convenience routine for doing a reverse lookup of an address"
***************
*** 19,22 ****
--- 22,42 ----
return Base.DnsRequest(b, qtype = 'ptr').req().answers[0]['data']
+ def revlookup6(name):
+ """Takes an IPv6 textual address (rfc 2373 2.2 presentation format (subpart 3, ::i.p.v.4
+ is explicitly NOT supported). Returns a name (only one if more than one presented)."""
+ a = Lib.addr62bin(name)
+ s = '%08x%08x%08x%08x' % a
+ l = list(s)
+ l.reverse()
+ s = '.'
+ s = s.join(l)
+ q = Base.DnsRequest(s + '.ip6.int',qtype='PTR').req()
+ # ip6.int is the 'legacy' domain but ip6.arpa is still missing
+ # several key zone cuts, including 2.0.0.2.ip6.arpa
+ if q.header['status'] == 'NXDOMAIN':
+ q = Base.DnsRequest(s + '.ip6.arpa',qtype='PTR').req()
+ return q.answers[0]['data']
+
+
def mxlookup(name):
"""
***************
*** 31,34 ****
--- 51,57 ----
#
# $Log$
+ # Revision 1.6 2002/05/08 15:05:34 dbt
+ # AAAA records and ip6.int/ip6.arpa reverse.
+ #
# Revision 1.5 2002/05/06 06:14:38 anthonybaxter
# reformat, move import to top of file.
|