diff options
| author | aagbsn <aagbsn@extc.org> | 2012-02-28 13:21:50 -0800 |
|---|---|---|
| committer | aagbsn <aagbsn@extc.org> | 2012-05-29 17:29:35 -0700 |
| commit | 3bee35c8d3977d0645bd57b8fc7bf4ef003538af (patch) | |
| tree | b10724b4508d553e1306f94c76f0a650f6cd08cd | |
| parent | ee4d719b3dcd99ab60c6d1db14302abe62667959 (diff) | |
4297 - ipv6 uniformMap
Adds an ipv6-comptabile uniform mapper.
| -rw-r--r-- | lib/bridgedb/Dist.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/bridgedb/Dist.py b/lib/bridgedb/Dist.py index 6a459be..95fe0b5 100644 --- a/lib/bridgedb/Dist.py +++ b/lib/bridgedb/Dist.py @@ -12,6 +12,7 @@ import bridgedb.Storage import logging import re import time +from ipaddr import IPv6Address, IPAddress def uniformMap(ip): """Map an IP to an arbitrary 'area' string, such that any two /24 addresses @@ -20,7 +21,10 @@ def uniformMap(ip): >>> uniformMap('1.2.3.4') '1.2.3' """ - return ".".join( ip.split(".")[:3] ) + if type(IPAddress(ip)) is IPv6Address: + return ":".join(IPv6Address(ip).exploded.split(':')[:4]) + else: + return ".".join( ip.split(".")[:3] ) class IPBasedDistributor(bridgedb.Bridges.BridgeHolder): """Object that hands out bridges based on the IP address of an incoming |
