This is a simple Python library for anonymizing IP addresses. Both IPv4 and IPv6 addresses are supported.
pip install anonymizeip
from anonymizeip import anonymize_ip address = "fe80::0202:b3ff:fe1e:8329" anonymized = anonymize_ip(address) print(anonymized) # Prints "fe80::"
The number of address blocks that are set to 0 can be customized.
Besides the IP address, the function
anonymize_ip takes two optional parameters:
anonymize_ip( address, ipv4_mask="...", ipv6_mask="..." )
ipv4_mask: Defaults to
255.255.255.0, i.e. the last octet will be anonymized (set to 0)
ipv6_mask: Defaults to
ffff:ffff:ffff:ffff:0:0:0:0), i.e. the last four blocks will be anonymized (set to 0)
pipenv install --dev
- Make your code modifications
pipenv run test
pipenv run lint
Contributions are always welcome. Please first discuss changes via issue before submitting a pull request.
The implementation of this library was strongly inspired by php-ip-anonymizer by Geert Wirken.