https://github.com/samuelmeuli/anonymize-ip
👤 Python library for anonymizing IP addresses
https://github.com/samuelmeuli/anonymize-ip
anonymization ip-address privacy
Last synced: over 1 year ago
JSON representation
👤 Python library for anonymizing IP addresses
- Host: GitHub
- URL: https://github.com/samuelmeuli/anonymize-ip
- Owner: samuelmeuli
- License: mit
- Created: 2018-08-24T21:33:22.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-11-08T19:58:57.000Z (over 6 years ago)
- Last Synced: 2025-02-27T04:08:55.848Z (over 1 year ago)
- Topics: anonymization, ip-address, privacy
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```
```py
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:
```py
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::` (same as `ffff:ffff:ffff:ffff:0:0:0:0`), i.e. the last four blocks will be anonymized (set to 0)
## Development
1. `git clone`
2. `pipenv install --dev`
3. Make your code modifications
4. `pipenv run test`
5. `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](https://github.com/geertw/php-ip-anonymizer) by Geert Wirken.