Skip to main content

IPv4 Conversions

ipv4-conversions converts an IPv4 address between dotted-decimal notation and four dotted 8-bit binary octets. It is available as a Python library, a command-line tool, and an interactive prompt.

Requirements

Installation

pip install .

Library usage

from ipv4_conversions import binary_to_ipv4, ipv4_to_binary

ipv4_to_binary("192.168.1.1")
# "11000000.10101000.00000001.00000001"

binary_to_ipv4("11000000.10101000.00000001.00000001")
# "192.168.1.1"

Both functions require exactly four octets. Decimal octets must be in the range 0 to 255; binary octets must each contain exactly eight 0 or 1 characters. Invalid input raises ValueError.

Function Description
ipv4_to_binary(ipv4: str) -> str Converts dotted-decimal IPv4 notation to four zero-padded, dotted binary octets.
binary_to_ipv4(binary: str) -> str Converts four dotted 8-bit binary octets to dotted-decimal IPv4 notation.

Command line

# Binary address to dotted decimal
ipv4-conversions --to-decimal 11000000.10101000.00000001.00000001
# The dotted-decimal equivalent of ... is: 192.168.1.1

# Dotted decimal to binary address
ipv4-conversions --to-binary 192.168.1.1
# The binary equivalent of 192.168.1.1 is: 11000000.10101000.00000001.00000001

The short options are -d for --to-decimal and -b for --to-binary. The options are mutually exclusive.

For each option, you can insert one or more addresses, and the program will output multiple conversions. For example:

ipv4-conversions --to-binary 192.168.0.0 192.168.1.0
# The binary equivalent of 192.168.0.0 is: 11000000.10101000.00000000.00000000
# The binary equivalent of 192.168.1.0 is: 11000000.10101000.00000001.00000000

Also, you can shorten the output to the sole result with '-s' or '--short' flag:

ipv4-conversions --to-binary 192.168.0.1 --short
# 11000000.10101000.00000000.00000001

Running ipv4-conversions without options opens the interactive menu.

Interactive menu

Run the command without any options to open the interactive menu:

ipv4-conversions

Choose Binary address to dotted decimal or Dotted decimal to binary address, then enter the address when prompted. Choose Exit to quit.

Development

You can install development tools, such as pytest and ruff, using this command:

pip install -e ".[dev]"

Test suite

The pytest suite covers valid conversions in both directions, round-trip conversions, and invalid IPv4 and binary input; aswell as CLI prompts (via flags or interactive menu), and invalid flag usage. Run it from the project root with:

python3 -m pytest

Project structure

ipv4_conversions/
├── .gitignore
├── LICENSE
├── pyproject.toml
├── README.md
├── src/
│   └── ipv4_conversions/
│       ├── __init__.py
│       ├── cli.py
│       └── core.py
└── tests/
    ├── test_conversions.py
    └── test_invalid.py

License

Released under the MIT License. See LICENSE.

Metadata

Release files for ipv4-conversions 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ipv4-conversions 1.0.0
File Size Uploaded Provenance Actions
ipv4_conversions-1.0.0.tar.gz 6.4 kB Without provenance Details for ipv4_conversions-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ipv4-conversions 1.0.0
File Interpreter ABI Platform Actions
ipv4_conversions-1.0.0-py3-none-any.whl Python 3 none any Details for ipv4_conversions-1.0.0-py3-none-any.whl

Total release size: 12.1 kB

Release files / ipv4_conversions-1.0.0.tar.gz

Download URL ipv4_conversions-1.0.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
09f7061c91683a4752a6ec1c27d631629d323404cf9e963de983d54dded05e2c
BLAKE2b-256 checksum
How to use checksums
790e5d11fe4966df63a94d5d6eb911bac1868a16abafeb9b75dfed39e0b9345b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / ipv4_conversions-1.0.0-py3-none-any.whl

Download URL ipv4_conversions-1.0.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1340509332ba3c69db0f76e2dc0e333b67ed094343553abcf24f83db8db3b486
BLAKE2b-256 checksum
How to use checksums
6ffc969f7830f0c6debe78a645035624891b8b405bfb64debf465e252cfcf494
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for ipv4-conversions 1.0.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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page