cidr-aggregator
Aggregate, normalize, reverse, and difference CIDR (IP range) entries. Both IPv4 and IPv6 are supported.
Features
- Aggregate — merge overlapping and adjacent CIDR ranges into a minimal set
- Reverse — compute the complement (all IPs not in the given ranges)
- Difference — subtract one set of ranges from another
- Normalize — split non-canonical ranges into proper CIDR blocks
- Exclude reserved — filter out special-purpose addresses (RFC 5735, RFC 6890)
- IPv4 + IPv6 — unified API via the
IpRangetrait
Usage
CLI
Install with Cargo:
Pipe CIDRs from stdin:
|
|
Read from a file:
Reverse (compute complement of all input ranges):
Exclude reserved/private IPs:
Show statistics (address count, line count):
Library
Add to your Cargo.toml:
[]
= "0.1"
Aggregate overlapping and adjacent blocks into a minimal set:
use ;
let = parse_cidrs;
// Adjacent .0.0/24 + .1.0/24 → .0.0/23; .0.128/25 is inside the /23
v4_ranges.aggregate;
// Aggregate produces minimal ranges but not necessarily canonical CIDR
// blocks — normalize() is required before export().
v4_ranges.normalize;
assert_eq!;
Chain operations in a pipeline — filter reserved addresses, then reverse:
use ;
let = parse_cidrs;
println!;
See the API documentation for all available operations.
Web App
Also available as a WASM-powered web app at:
License
MIT OR Apache-2.0