Skip to content

Commit

Permalink
Merge branch 'fix/15522-ipv6-enumeration' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
isislovecruft committed Mar 31, 2015
2 parents 83e84d1 + c91def0 commit 0341b72
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/bridgedb/Dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ class EmailRequestedKey(Exception):
def uniformMap(ip):
"""Map an IP to an arbitrary 'area' string, such that any two IPv4
addresses in the same ``/16`` subnet, or any two IPv6 addresses in the
same ``/64`` subnet, get the same string.
same ``/32`` subnet, get the same string.
>>> from bridgedb import Dist
>>> Dist.uniformMap('1.2.3.4')
'1.2.0.0/16'
>>> Dist.uniformMap('1.2.211.154')
'1.2.0.0/16'
>>> Dist.uniformMap('2001:f::bc1:b13:2808')
'2001:f::/64'
'2001:f::/32'
>>> Dist.uniformMap('2a00:c98:2030:a020:2::42')
'2a00:c98:2030:a020::/64'
'2a00:c98::/32'
:param str ip: A string representing an IPv4 or IPv6 address.
:rtype: str
Expand All @@ -71,8 +71,8 @@ def uniformMap(ip):
# in a hashring.
address = ipaddr.IPAddress(ip)
if address.version == 6:
truncated = ':'.join(address.exploded.split(':')[:4])
subnet = str(ipaddr.IPv6Network(truncated + "::/64"))
truncated = ':'.join(address.exploded.split(':')[:2])
subnet = str(ipaddr.IPv6Network(truncated + "::/32"))
return subnet
else:
truncated = '.'.join(address.exploded.split('.')[:2])
Expand Down

0 comments on commit 0341b72

Please sign in to comment.