ip2cidr
A Python tool to convert IP addresses to /24 CIDR notation.
Installation
pip install ip2cidr
Usage
The tool can be used from the command line:
# Convert a single IP
ip2cidr -i "10.200.2.132"
# Convert multiple IPs (comma-separated)
ip2cidr -i "10.200.2.132,192.168.1.100,172.16.5.200"
# Use a different separator for output (default is comma)
ip2cidr -i "10.200.2.132,192.168.1.100" -s " "
Arguments
-i, --ips: Required. Comma-separated list of IP addresses to convert-s, --separator: Optional. Output separator (default: comma)
Example Output
$ ip2cidr -i "10.200.2.132,192.168.1.100,172.16.5.200"
10.200.2.0/24,172.16.5.0/24,192.168.1.0/24
$ ip2cidr -i "10.200.2.132,192.168.1.100" -s " "
10.200.2.0/24 192.168.1.0/24
Python Usage
You can also use the tool in your Python code:
from ip_converter import ip_to_cidr
# Convert IPs to CIDR
ips = "10.200.2.132,192.168.1.100"
cidrs = ip_to_cidr(ips)
print(cidrs) # ['10.200.2.0/24', '192.168.1.0/24']
Development
Running Tests
To run the tests, first install the development dependencies:
pip install -e ".[test]"
Then run the tests with pytest:
pytest
This will run all tests and generate a coverage report. The tests cover various scenarios including:
- Single IP conversion
- Multiple IP conversion
- Duplicate network handling
- Invalid IP handling
- Empty input
- Whitespace handling
- Partial IP addresses
- Special IP addresses (localhost, etc.)
Features
- Converts IP addresses to their corresponding /24 CIDR networks
- Handles multiple IP addresses
- Removes duplicates and sorts the output
- Customizable output separator
- Error handling for invalid IP addresses
- Comprehensive test suite with 100% coverage
Requirements
- Python 3.8 or higher
- argparse>=1.4.0
License
MIT License
Metadata
Release files for ip2cidr 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ip2cidr-0.1.0.tar.gz | 3.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ip2cidr-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.0 kB
Release files / ip2cidr-0.1.0.tar.gz
| Download URL | ip2cidr-0.1.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8da54bed9aa12ce7f255895ce1805d0e31122efbcc5320cdee435e1aba227932
|
|
BLAKE2b-256 checksum How to use checksums |
fae8dd98b0f438b5813a9a20e8eeb8c53c56535337d6efa2c6a7acb69a236787
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / ip2cidr-0.1.0-py3-none-any.whl
| Download URL | ip2cidr-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7bd1ba2fb5fbd69cb2d3edded04078dfad1b4ce0144fb997ca23e9f9d2fbf050
|
|
BLAKE2b-256 checksum How to use checksums |
da899c8a4f230d9396b323b977a0aa2605637f957074f149461c042a29446721
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Security for ip2cidr 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.