use only first 3 bytes from an IPv6 address

This commit is contained in:
Martin Zimmermann 2013-09-13 16:13:45 +02:00
parent 7ed5d6461e
commit 021b672ee2

View File

@ -105,7 +105,7 @@ def anonymize(remote_addr):
ip = ipaddress.ip_address(remote_addr) ip = ipaddress.ip_address(remote_addr)
if ip.version == "4": if ip.version == "4":
return ''.join(ip.exploded.rsplit('.', 1)[0]) + '.' + '0' return ''.join(ip.exploded.rsplit('.', 1)[0]) + '.' + '0'
return ip.exploded.rsplit(':', 4)[0] return ip.exploded.rsplit(':', 5)[0]
def salt(value, s=u'\x082@t9*\x17\xad\xc1\x1c\xa5\x98'): def salt(value, s=u'\x082@t9*\x17\xad\xc1\x1c\xa5\x98'):