Subnet Calc
CIDR/subnet calculator CLI. IPv4 and IPv6 support with no external dependencies.
Quick Start
CODEBLOCK0
Output Fields (IPv4)
- - CIDR — Normalized CIDR notation
- Network/Broadcast Address — First and last address in the range
- Subnet Mask / Wildcard Mask — Standard and inverted masks
- Total Addresses / Usable Hosts — Address count minus network and broadcast
- First/Last Host — Usable host range
- Binary representations — Network and mask in binary
- Flags — Private, loopback, multicast, link-local detection
Options
| Flag | Description |
|---|
| INLINECODE0 | INLINECODE1 or json output |
| INLINECODE3 |
Check if IP is within the network |
|
--split PREFIX | Split into subnets with given prefix (IPv4) |
Notes
- - Python 3 stdlib only (uses
ipaddress module) - Handles /31 (RFC 3021 point-to-point) and /32 correctly
- Input is normalized with
strict=False (host bits are masked)
Subnet Calc
CIDR/子网计算器命令行工具。支持IPv4和IPv6,无外部依赖。
快速开始
bash
基本子网计算
python3 scripts/subnet_calc.py 192.168.1.0/24
JSON格式输出
python3 scripts/subnet_calc.py 10.0.0.0/8 -f json
检查IP是否在网络内
python3 scripts/subnet_calc.py 172.16.0.0/16 --contains 172.16.5.10
分割为更小的子网
python3 scripts/subnet_calc.py 192.168.0.0/22 --split 24
IPv6
python3 scripts/subnet_calc.py 2001:db8::/32
输出字段(IPv4)
- - CIDR — 标准化CIDR表示法
- 网络/广播地址 — 地址范围中的第一个和最后一个地址
- 子网掩码/通配符掩码 — 标准掩码和反向掩码
- 总地址数/可用主机数 — 地址总数减去网络地址和广播地址
- 第一个/最后一个主机 — 可用主机范围
- 二进制表示 — 网络地址和掩码的二进制形式
- 标志 — 私有、回环、组播、链路本地检测
选项
| 标志 | 描述 |
|---|
| -f, --format | plain 或 json 输出格式 |
| --contains IP |
检查IP是否在网络范围内 |
| --split PREFIX | 按给定前缀分割为子网(IPv4) |
说明
- - 仅使用Python 3标准库(使用ipaddress模块)
- 正确处理/31(RFC 3021点对点)和/32
- 输入使用strict=False进行标准化(主机位被掩码)