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

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

pip install -e ".[dev]"
python3 -m pytest
ruff format
ruff check .

License

Released under the MIT License. See LICENSE.

Metadata

Release files for ipv4-conversions 0.2.1

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 0.2.1
File Size Uploaded Provenance Actions
ipv4_conversions-0.2.1.tar.gz 5.0 kB Without provenance Details for ipv4_conversions-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 10.3 kB

Release files / ipv4_conversions-0.2.1.tar.gz

Download URL ipv4_conversions-0.2.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
10912ea0d9ae42686e446a308b675a58f602dca7b27eb1af1055bd2dc6155055
BLAKE2b-256 checksum
How to use checksums
6c40277a475980791c962264894173ab2839dc43027e96da7240bb4b85f3583a
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-0.2.1-py3-none-any.whl

Download URL ipv4_conversions-0.2.1-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e1d62d644d7bc9e766f096ea2229a02f5188f4f1f57a98377cd0f9d680593ac
BLAKE2b-256 checksum
How to use checksums
8b3d52db315b3040b58d5470a0b6a4ece3878af3837b4616684d52c76ee38de6
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 0.2.1

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