A CLI tool that is useful for quickly checking and filtering data by IP vs. CIDR blocks.
Please see the docs for details on the commands.
$ cidr --help NAME: cidr - tool for checking IPs against CIDR blocks USAGE: cidr [global options] command [command options] [arguments...] AUTHOR: Derek Smith <email@example.com> COMMANDS: check, c Check IP against range of CIDR blocks filter, f Filters lines in log files of pipe input version, v Print version info help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --help, -h show help (default: false) COPYRIGHT: (c) 2022 Derek Smith
- Use Cases
check command allows for a quick check of a list of IPs and Blocks.
$ cidr check --blocks 22.214.171.124/16,126.96.36.199/16 --ips 188.8.131.52,184.108.40.206,220.127.116.11/32 18.104.22.168/32 is in CIDR 22.214.171.124/16 126.96.36.199/32 is NOT in CIDR set 188.8.131.52/32 is in CIDR 184.108.40.206/16
filter command is useful for filtering large data sets like access log files.
$ cidr filter --blocks 10.2.120.0/8,10.2.122.0/8,10.20.128.20/29 --path '/var/log/http/**/access*.log' < outputs to STDOUT all lines that contain an IP that is within a CIDR blocks provided >
filter command can also be used with a pipe.
$ cidr filter --blocks 10.2.120.0/8,10.2.122.0/8,10.20.128.20/29 < /var/log/http/access-20220120-18.log < outputs to STDOUT all lines that contain an IP that is within a CIDR blocks provided >
filter command accepts the
--inverse, i flag which will output all lines that DO NOT contain
an IP within a CIDR block provided. If a line has multiple IP addresses within it, then ALL IPs must not be within
a CIDR block for the line to be output to
$ cidr filter --blocks 10.2.120.0/8,10.2.122.0/8,10.20.128.20/29 --path '/var/log/http/**/access*.log' --inverse < outputs to STDOUT all lines that DO NOT contain an IP that is within a CIDR blocks provided >
Homebrew (for macOS users)
brew tap clok/cidr brew install cidr
$ curl https://i.jpillora.com/clok/cidr! | bash
The compiled docker images are maintained on GitHub Container Registry (ghcr.io). We maintain the following tags:
edge: Image that is build from the current
HEADof the main line branch.
latest: Image that is built from the latest released version
x.y.z(versions): Images that are build from the tagged versions within Github.
docker pull ghcr.io/clok/cidr docker run -v "$PWD":/workdir ghcr.io/clok/cidr --version
$ cidr install-manpage
- Fork the clok/cidr repo
go >= 1.17
- Branch & Code
- Run linters :broom:
- The project uses golangci-lint
- Commit with a Conventional Commit
- Open a PR
- Derek Smith - @clok
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details