diff options
author | pmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035> | 2011-01-12 22:56:36 +0000 |
---|---|---|
committer | pmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035> | 2011-01-12 22:56:36 +0000 |
commit | 121f519665fe98a59c5a836c57afeedcdd381c7f (patch) | |
tree | ce8326f492fc6d52872b05ac84b001127cd76d1c | |
parent | eb1dbcedad214367cc402cdca14e97074ed3ff1b (diff) | |
download | ipaddr-py-121f519665fe98a59c5a836c57afeedcdd381c7f.tar.gz |
+ fix for i71
add support for pulling the teredo client and server addresses out
of an ipv6 address.
git-svn-id: https://ipaddr-py.googlecode.com/svn@199 09200d28-7f98-11dd-ad27-0f66e57d2035
-rw-r--r-- | trunk/ipaddr.py | 16 | ||||
-rwxr-xr-x | trunk/ipaddr_test.py | 8 |
2 files changed, 23 insertions, 1 deletions
diff --git a/trunk/ipaddr.py b/trunk/ipaddr.py index e0c847a..0e35858 100644 --- a/trunk/ipaddr.py +++ b/trunk/ipaddr.py @@ -29,6 +29,7 @@ import struct IPV4LENGTH = 32 IPV6LENGTH = 128 + class AddressValueError(ValueError): """A Value Error related to the address.""" @@ -1748,6 +1749,20 @@ class _BaseV6(object): except AddressValueError: return None + def teredo(self): + """Tuple of embedded teredo IPs. + + Returns: + Tuple of the (server, client) IPs. + + Note: + This doesn't try to verify that the address is a teredo address + """ + server_bits = self._explode_shorthand_ip_string().split(':')[2:4] + client_bits = self._explode_shorthand_ip_string().split(':')[6:] + return (IPv4Address(int(''.join(server_bits), 16)), + IPv4Address(int(''.join(client_bits), 16) ^ 0xFFFFFFFF)) + class IPv6Address(_BaseV6, _BaseIP): @@ -1898,7 +1913,6 @@ class IPv6Network(_BaseV6, _BaseNet): raise ValueError('%s has host bits set' % self.ip) - def _is_valid_netmask(self, prefixlen): """Verify that the netmask/prefixlen is valid. diff --git a/trunk/ipaddr_test.py b/trunk/ipaddr_test.py index f4e06fa..739c5f6 100755 --- a/trunk/ipaddr_test.py +++ b/trunk/ipaddr_test.py @@ -1017,5 +1017,13 @@ class IpaddrUnitTest(unittest.TestCase): self.assertFalse(ip._is_valid_ip('2001:658:22a:zzzz:200::1')) self.assertFalse(ip._is_valid_ip('2001:658:22a:cafe1:200::1')) + def testTeredo(self): + # stolen from wikipedia + server = ipaddr.IPv4Address('65.54.227.120') + client = ipaddr.IPv4Address('192.0.2.45') + teredo_addr = '2001:0000:4136:e378:8000:63bf:3fff:fdd2' + self.assertEqual((server, client), + ipaddr.IPAddress(teredo_addr).teredo()) + if __name__ == '__main__': unittest.main() |