Skip to main content

🧮 SubnetCalc – Fast IP Subnetting Calculator

A lightweight and efficient Python tool to perform subnetting operations on IPv4 addresses.
It can be used both as a standalone CLI utility and as a reusable module in your Python projects.


📦 Features

  • Accepts IP addresses with or without CIDR notation (e.g. 192.168.1.1 or 192.168.1.1/24)
  • Calculates:
    • IP address
    • CIDR prefix
    • Binary and decimal netmask
    • Network ID
    • Broadcast address
    • First and last usable IPs
    • All usable IPs in the subnet (as a generator)
  • Built with static conversion methods (binary ↔ decimal), reusable without class instantiation
  • Fully functional from the command line or as an importable Python class

🚀 Usage

1. CLI (Command-Line Interface)

python3 subnetcalc.py -i 192.168.1.1/24
[+] IP --> 192.168.1.1
[+] CIDR --> 24
[+] Netmask --> 255.255.255.0
[+] Network ID --> 192.168.1.0
[+] Broadcast --> 192.168.1.255
[+] Min / Max IP --> ('192.168.1.1', '192.168.1.254')

2. Import as a Module

from subnetcalc import Ip

my_ip = Ip("10.0.0.1/26")
print(my_ip.network_ip)       # 10.0.0.0
print(my_ip.broadcast)        # 10.0.0.63
print(list(my_ip.available_ips))  # List of usable IPs

🔧 Class & Methods

Class: Ip

Constructor

ip_instance = Ip("192.168.1.0/24")

Creates a new subnet object from an IP address string, with or without CIDR.

Attributes
  • ip → base IP address (string)

  • cidr → subnet prefix (e.g. '24')

  • netmask → human-readable subnet mask (e.g. '255.255.255.0')

  • network_ip → network ID

  • broadcast → broadcast address

  • min_max_ip → tuple of (first usable, last usable) IPs

  • available_ips → generator that yields all usable IPs in the subnet


Static Methods

These can be called without creating an object:

ip_to_bin(ip: str) → str

Converts a dotted-decimal IP to its 32-bit binary representation.

bin_to_ip(bin: str) → str

Converts a 32-bit binary string back to a dotted-decimal IP.

ip_to_dec(ip: str) → int

Converts a dotted-decimal IP to a 32-bit integer.

dec_to_ip(entero: int) → str

Converts a 32-bit integer to a dotted-decimal IP.


📁 Example:

from subnetcalc import Ip

ip = Ip("172.16.5.9/28")
print("Netmask:", ip.netmask)
print("First usable IP:", ip.min_max_ip[0])
print("Broadcast:", ip.broadcast)

# Iterate through usable IPs
for host in ip.available_ips:
    print(host)

Metadata

Release files for subnetcalc 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 subnetcalc 1.0.0
File Size Uploaded Provenance Actions
subnetcalc-1.0.0.tar.gz 3.5 kB Without provenance Details for subnetcalc-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 7.3 kB

Release files / subnetcalc-1.0.0.tar.gz

Download URL subnetcalc-1.0.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e8696ec08562f361cf13e0237db9fbacb7f534749d72c2476e428983b32cae7e
BLAKE2b-256 checksum
How to use checksums
4f1b3d2a38d2732c84338ac955c1a172f232ecfbbcf125274cac233a019b972d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

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

Download URL subnetcalc-1.0.0-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
415831b7861546798e34950d86aa109d0ac106c638c7d4930c149c7d58eb08ac
BLAKE2b-256 checksum
How to use checksums
d9a4099fa2a07b0a51260f2c197632ab7e1af19033d5352110325c4bffe2e15e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Security for subnetcalc 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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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