Python library for anonymizing IP addresses
Project description
anonymize_ip
This is a simple Python library for anonymizing IP addresses. Both IPv4 and IPv6 addresses are supported.
Examples:
- IPv4:
95.239.169.11
→95.239.169.0
- IPv6:
5219:3a94:fdc5:19e1:70a3:b2c4:40ef:ae03
→5219:3a94:fdc5:19e1::
Usage
pip install anonymizeip
from anonymizeip import anonymize_ip address = "fe80::0202:b3ff:fe1e:8329" anonymized = anonymize_ip(address) print(anonymized) # Prints "fe80::"
Settings
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 to255.255.255.0
, i.e. the last octet will be anonymized (set to 0)ipv6_mask
: Defaults toffff:ffff:ffff:ffff::
(same asffff:ffff:ffff:ffff:0:0:0:0
), i.e. the last four blocks will be anonymized (set to 0)
Development
git clone
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.
Credits
The implementation of this library was strongly inspired by php-ip-anonymizer by Geert Wirken.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size anonymizeip-1.0.0-py2.py3-none-any.whl (3.4 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes View |
Filename, size anonymizeip-1.0.0.tar.gz (4.3 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for anonymizeip-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0d446b06b2bbf236394a90b971de403f90f805d14db3a405f8731716acad1fe |
|
MD5 | a2c39bb478df8ad2752d99dbed7b59d7 |
|
BLAKE2-256 | e27427c04c380b9e5d40de1643677f07b54bda2733b33cabba809214405a737e |