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.
Project description
🧮 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.1or192.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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file subnetcalc-1.0.0.tar.gz.
File metadata
- Download URL: subnetcalc-1.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8696ec08562f361cf13e0237db9fbacb7f534749d72c2476e428983b32cae7e
|
|
| MD5 |
fc151a7c50b781770040b828f1894aac
|
|
| BLAKE2b-256 |
4f1b3d2a38d2732c84338ac955c1a172f232ecfbbcf125274cac233a019b972d
|
File details
Details for the file subnetcalc-1.0.0-py3-none-any.whl.
File metadata
- Download URL: subnetcalc-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
415831b7861546798e34950d86aa109d0ac106c638c7d4930c149c7d58eb08ac
|
|
| MD5 |
e21462d7494def1e149a44380a1cc6c0
|
|
| BLAKE2b-256 |
d9a4099fa2a07b0a51260f2c197632ab7e1af19033d5352110325c4bffe2e15e
|