cidrex
is a command-line utility for expanding IP addresses and CIDR ranges. It reads IP addresses and CIDR ranges from a file or stdin, and outputs all individual IP addresses contained within them. The utility supports both IPv4 and IPv6 addresses.
- Supports reading from a specified file or standard input (stdin).
- Expands CIDR ranges into individual IP addresses.
- Supports filtering only IPv4, only IPv6, or both types of addresses.
To install cidrex
, you need to have Go installed on your system. You can then install the binary using the following commands:
go install github.com/d3mondev/cidrex@latest
cidrex [OPTIONS] [filename]
If no filename is provided, cidrex reads from stdin.
-4, --ipv4
: Print only IPv4 addresses-6, --ipv6
: Print only IPv6 addresses-h, --help
: Display the help message
- Expand IP addresses and CIDR ranges from a file:
cidrex input.txt
- Expand only IPv4 addresses from a file:
cidrex -4 input.txt
- Expand only IPv6 addresses from stdin:
cat input.txt | cidrex -6
The input should contain one IP address or CIDR range per line. For example:
192.168.1.1
10.0.0.0/24
2001:db8::1
2001:db8::/120
The program outputs one IP address per line. For individual IP addresses, it simply outputs the address as-is. For CIDR ranges, it expands the range and outputs each individual IP address within that range.
If the program encounters any errors (e.g., invalid IP addresses or CIDR ranges), it will print error messages to stderr and continue processing the remaining input.