cidr

A CLI tool that is useful for quickly checking and filtering data by IP vs. CIDR blocks.

Readme Card

License: MIT Go Report Card Coverage Status go.dev reference

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 <me@clok.sh>

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

The check command allows for a quick check of a list of IPs and Blocks.

$ cidr check --blocks 172.12.0.0/16,172.10.0.0/16 --ips 172.12.1.56,171.10.123.57,172.10.0.255/32
172.12.1.56/32 is in CIDR 172.12.0.0/16
171.10.123.57/32 is NOT in CIDR set
172.10.0.255/32 is in CIDR 172.10.0.0/16

The 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 >

The 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 >

Finally, the 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 STDOUT.

$ 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 >

Installation

Homebrew (for macOS users)

brew tap clok/cidr
brew install cidr

curl binary

$ curl https://i.jpillora.com/clok/cidr! | bash

docker

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 HEAD of 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

man page

To install man page:

$ cidr install-manpage

Development

  1. Fork the clok/cidr repo
  2. Use go >= 1.17
  3. Branch & Code
  4. Run linters :broom: golangci-lint run
  5. Commit with a Conventional Commit
  6. Open a PR

Versioning

We employ git-chglog to manage the CHANGELOG.md. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details