subnetCalc

command module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

subnetCalc

Description

This is a Go CLI utility (built with Cobra) to calculate network information from a CIDR.

It can also split a “supernet” into smaller subnets and render the result either as a styled table or JSON. There is also an optional interactive TUI for splitting/joining subnets.

IPv4 is the primary target. IPv6 works for basic calculations/output, but deeper functionality (especially around very large splits) is intentionally limited.

Usage

subnetCalc <ip address>/<subnet mask>

Flags
  • --subnet-size, -s — split the input network into subnets of this prefix length
  • --json, -j — output JSON
  • --interactive, -i — launch the interactive TUI (mutually exclusive with --json)
  • --verbose, -v — increase verbosity (repeat for more)
Interactive TUI Key Bindings

When using --interactive mode:

  • ↑/k — move cursor up
  • ↓/j — move cursor down
  • ←/h — scroll split columns left
  • →/l — scroll split columns right
  • pgup — page up through rows
  • pgdn — page down through rows
  • s — split selected subnet
  • x — join selected subnet with sibling
  • u — undo last split/join operation
  • r — redo last undone operation
  • e — export tree as JSON
  • c — copy JSON to clipboard
  • ? — toggle help display
  • q — quit

Examples

List /12 Subnets Contained in a /8 Network Using the Interactive TUI

svg

Get Network Information for a /19 Network

subnetCalc 10.12.34.56/19

               Network: 10.12.32.0/19
    Host Address Range: 10.12.32.1 - 10.12.63.254
     Broadcast Address: 10.12.63.255
           Subnet Mask: 255.255.224.0
         Maximum Hosts: 8,190
List /27 Subnets Contained in a /25 Network

subnetCalc 192.168.10.0/25 --subnet-size 27

               Network: 192.168.10.0/25
    Host Address Range: 192.168.10.1 - 192.168.10.126
     Broadcast Address: 192.168.10.127
           Subnet Mask: 255.255.255.128
         Maximum Hosts: 126

  192.168.10.0/25 contains 4 /27 subnets:
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ #   Subnet              Subnet Mask     Assignable Range              Broadcast       Hosts      │
│1   192.168.10.0/27     255.255.255.224 192.168.10.1 - 192.168.10.30  192.168.10.31   30          │
│2   192.168.10.32/27    255.255.255.224 192.168.10.33 - 192.168.10.62 192.168.10.63   30          │
│3   192.168.10.64/27    255.255.255.224 192.168.10.65 - 192.168.10.94 192.168.10.95   30          │
│4   192.168.10.96/27    255.255.255.224 192.168.10.97 - 192.168.10.126192.168.10.127  30          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
List /20 Subnets Contained in a /19 Network in JSON Format

subnetCalc 10.12.34.56/19 --subnet-size 20 --json

{
  "cidr": "10.12.32.0/19",
  "firstIP": "10.12.32.1",
  "lastIP": "10.12.63.254",
  "networkAddr": "10.12.32.0",
  "broadcastAddr": "10.12.63.255",
  "subnetMask": "255.255.224.0",
  "maskBits": 19,
  "maxHosts": "8,190",
  "subnets": [
    {
      "cidr": "10.12.32.0/20",
      "firstIP": "10.12.32.1",
      "lastIP": "10.12.47.254",
      "networkAddr": "10.12.32.0",
      "broadcastAddr": "10.12.47.255",
      "subnetMask": "255.255.240.0",
      "maskBits": 20,
      "maxHosts": "4,094"
    },
    {
      "cidr": "10.12.48.0/20",
      "firstIP": "10.12.48.1",
      "lastIP": "10.12.63.254",
      "networkAddr": "10.12.48.0",
      "broadcastAddr": "10.12.63.255",
      "subnetMask": "255.255.240.0",
      "maskBits": 20,
      "maxHosts": "4,094"
    }
  ]
}

Notes / Limitations

  • --subnet-size will refuse to generate an extremely large number of subnets (currently capped at 1,000,000) to avoid accidental OOM/hangs.
  • IPv6 output is supported, but some concepts (like “broadcast”) are displayed as the last address in the range.

Feedback

Bug reports, feature requests, and pull requests are welcome but may not be responded to in an even remotely timely manner.

Documentation

Overview

Copyright © 2025 Jake Rogers <code@supportoss.org>

Directories

Path Synopsis
Package formatter provides output formatting interfaces and implementations.
Package formatter provides output formatting interfaces and implementations.
internal
ui
Package ui provides shared styling and UI components for subnetCalc.
Package ui provides shared styling and UI components for subnetCalc.
Package logger provides a zerolog-based logger with verbosity levels.
Package logger provides a zerolog-based logger with verbosity levels.
Package subnet provides core domain types and calculations for IP subnet operations.
Package subnet provides core domain types and calculations for IP subnet operations.
Package tui provides an interactive terminal user interface for subnet calculations.
Package tui provides an interactive terminal user interface for subnet calculations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL