Skip to content
Snippets Groups Projects
Commit 3bee35c8 authored by aagbsn's avatar aagbsn
Browse files

4297 - ipv6 uniformMap

Adds an ipv6-comptabile uniform mapper.
parent ee4d719b
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment