MCPcopy
hub / github.com/isso-comments/isso / anonymize

Function anonymize

isso/utils/__init__.py:16–34  ·  view source on GitHub ↗

Anonymize IPv4 and IPv6 :param remote_addr: to /24 (zero'd) and /48 (zero'd).

(remote_addr)

Source from the content-addressed store, hash-verified

14
15
16def anonymize(remote_addr):
17 """
18 Anonymize IPv4 and IPv6 :param remote_addr: to /24 (zero'd)
19 and /48 (zero'd).
20
21 """
22 if isinstance(remote_addr, bytes):
23 remote_addr = remote_addr.decode("ascii", "ignore")
24 try:
25 ipv4 = ipaddress.IPv4Address(remote_addr)
26 return "".join(ipv4.exploded.rsplit(".", 1)[0]) + "." + "0"
27 except ipaddress.AddressValueError:
28 try:
29 ipv6 = ipaddress.IPv6Address(remote_addr)
30 if ipv6.ipv4_mapped is not None:
31 return anonymize(str(ipv6.ipv4_mapped))
32 return "" + ipv6.exploded.rsplit(":", 5)[0] + ":" + ":".join(["0000"] * 5)
33 except ipaddress.AddressValueError:
34 return "0.0.0.0"
35
36
37class Bloomfilter:

Callers 2

migrateMethod · 0.90
CommentMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected