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

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

Built distribution (wheel)

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

Total release size: 10.5 kB

Release files / ipv4_conversions-0.3.0.tar.gz

Download URL ipv4_conversions-0.3.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e71d4d0e16f7b49f010278f66561b7c2c55265a04a7efa82e71949c38eca0c7f
BLAKE2b-256 checksum
How to use checksums
14edbd4edf35dc06a543489472c67cfa710e6c87e665859f5f7cf49398618ee4
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.3.0-py3-none-any.whl

Download URL ipv4_conversions-0.3.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
503649bbee11385cb4fa0dcb018ec71c375dd3629a5a41def27d1ca57d6b5b42
BLAKE2b-256 checksum
How to use checksums
f9387e6bfc2668d492813d47cb34a6af196f0bb5ff94216a5caf24800ce289ad
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.3.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