Skip to content

RouteObjects/cidrwalk

Repository files navigation

cidrwalk icon  cidrwalk

cidrwalk is a small Swift command-line example built on swift-cidr. It demonstrates CIDR summarization with explicit input meaning instead of guessing from loosely typed strings.

The command is intentionally narrow and teaching-oriented:

  • addresses summarizes two CIDR-qualified host endpoints with /32 or /128.
  • networks summarizes the envelope covering two whole CIDR network prefixes.

Both inputs must be from the same IP address family. Reversed input order is normalized at the CLI boundary before calling into swift-cidr.

CIDR Aggregation

CIDR summarization converts an inclusive address range, or the envelope around two network prefixes, into the smallest ordered set of aligned CIDR prefixes. The result may be one prefix when the inputs align cleanly, or several prefixes when the range starts or ends inside a larger boundary.

The addresses subcommand requires /32 for IPv4 and /128 for IPv6 because those prefix lengths identify exact host endpoints. The networks subcommand accepts CIDR network prefixes and summarizes the full envelope that covers both inputs, including adjacent, nested, or reversed networks.

Usage

Homebrew

Install the released command-line tool from the RouteObjects tap:

brew install RouteObjects/tap/cidrwalk

Build From Source

Clone the repository and run the executable with SwiftPM:

git clone https://github.com/RouteObjects/cidrwalk.git
cd cidrwalk
swift run cidrwalk --help

Check the installed version with either version flag:

cidrwalk --version
cidrwalk -v

Address Endpoints

Use addresses when the inputs are host endpoints. Prefix notation is required, and only host-length prefix lengths are accepted.

swift run cidrwalk addresses 192.168.1.1/32 192.168.1.2/32
192.168.1.1/32
192.168.1.2/32

IPv6 host endpoints use /128:

swift run cidrwalk addresses 2001:db8::1/128 2001:db8::f/128

Network Prefixes

Use networks when the inputs are CIDR network prefixes. The output covers both complete input networks, including reversed, nested, or adjacent inputs.

swift run cidrwalk networks 192.0.2.0/24 192.0.3.0/24
192.0.2.0/23

JSON

JSON output is available with --output json:

swift run cidrwalk addresses 192.168.1.1/32 192.168.1.189/32 --output json
{
  "family" : "IPv4",
  "inputs" : [
    "192.168.1.1/32",
    "192.168.1.189/32"
  ],
  "mode" : "addresses",
  "prefixes" : [
    "192.168.1.1/32",
    "192.168.1.2/31",
    "192.168.1.4/30",
    "192.168.1.8/29",
    "192.168.1.16/28",
    "192.168.1.32/27",
    "192.168.1.64/26",
    "192.168.1.128/27",
    "192.168.1.160/28",
    "192.168.1.176/29",
    "192.168.1.184/30",
    "192.168.1.188/31"
  ],
  "rangeEnd" : "192.168.1.189/32",
  "rangeStart" : "192.168.1.1/32"
}

Tree

Tree output is available with --output tree. Indentation is based on prefix-length depth within the summarized result; it is a teaching visualization, not a proportional address-space diagram.

swift run cidrwalk addresses 192.0.2.1/32 192.0.2.6/32 --output tree
192.0.2.1/32
             192.0.2.2/31
             192.0.2.4/31
192.0.2.6/32

Testing

Use the repository test wrapper:

./scripts/test.sh

The wrapper still runs swift test. It only adds the Swift Testing framework and runtime paths needed by standalone Command Line Tools installations where plain swift test cannot locate Testing.framework.

About

cidrwalk is a small Swift command-line tool built on swift-cidr for teaching and inspecting CIDR range summarization with explicit IPv4/IPv6 address and network input semantics.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors