CLI tool for CIDR range operations (check, generate)

cidrchk

release

A CLI tool to assist you with CIDR ranges and IPs.

Install it

You can download the latest binary for Linux (Intel and Arm), macOS, and Windows.

For example, to install cidrchk from binary on macOS, do the following:

curl -L https://github.com/mhausenblas/cidrchk/releases/latest/download/cidrchk_darwin_amd64.tar.gz \
    -o cidrchk.tar.gz && \
    tar xvzf cidrchk.tar.gz cidrchk && \
    mv cidrchk /usr/local/bin && \
    rm cidrchk*

Use it

cidrchk can do three things for you: 1. check CIDR ranges for inclusion, 2. check for CIDR range overlaps, and 3. generate all IPs in a CIDR range.

Note that cidrchk uses OPA Rego to perform CIDR operation, to be precise the built-in Net functions.

Check for CIDR range inclusion

To check if a CIDR range contains an IP or another CIDR range:

$ cidrchk contains 192.168.0.0/16 192.168.0.42
yes

This also works for IPv6 addresses, for example:

$ cidrchk contains \
          0:0:0:0:0:ffff:c0a8:0/30 \
          0:3:ffff:ffff:ffff:ffff:ffff:ffff
yes

Check for CIDR range overlaps

To check if two CIDR ranges overlap you can do:

$ cidrchk overlaps 192.168.0.0/16 192.168.1.0/24
yes

Generate IPs from CIDR range

To expand a CIDR range, that is, to generate all IPs in it do the following:

$ cidrchk expand 192.168.0.0/30 | jq .
{
  "cidr": "192.168.0.0/30",
  "ips": [
    [
      "192.168.0.0",
      "192.168.0.1",
      "192.168.0.2",
      "192.168.0.3"
    ]
  ]
}

One can also answer questions like "How many IP addresses are there in a CIDR range", for example:

$ cidrchk expand 192.168.0.0/16 | jq '.ips[] | length'
65536
Owner
Similar Resources

Symfony-cli - The Symfony CLI tool For Golang

Symfony CLI Install To install Symfony CLI, please download the appropriate vers

Dec 28, 2022

bcrypt-cli is the CLI tool for hashing passwords with bcrypt.

bcrypt-cli bcrypt-cli is the CLI tool for hashing passwords with bcrypt. Install go install github.com/ryicoh/bcrypt-cli Usage It can be used like bas

Jan 9, 2023

GTDF-CLI - The official CLI tool to operate with Getting Things Done Framework

GTDF-CLI - The official CLI tool to operate with Getting Things Done Framework

This is the official CLI tool to operate with Getting Things Done Framework. How

Feb 14, 2022

Generate Changelogs from Commits (CLI)

Commitlog Changelog generator using Commit History To see an example of this in action, you can check the actions file for this repo. Yes it uses itse

Sep 30, 2022

A simple CLI applet to generate 'White Noise' pictorial depictions.

A simple CLI applet to generate 'White Noise' pictorial depictions.

White Noise Generator A simple CLI applet written in Go to create pictorial representations of White Noise. Example Okay, but how? An output file of t

Nov 23, 2022

Easy to use library and CLI utility to generate Go struct from CSV files.

csv2struct Easy to use library and CLI utility to generate Go struct from CSV files. As a benefit, it's fully compatible with csvutil. So, structs gen

Nov 7, 2022

Powerful CLI written in GO to generate projects in various technologies

Powerful CLI written in GO to generate projects in various technologies

Barca CLI is a project generator written in GO and its purpose is to build and configure HTTP servers, web proxy, SPA/PWA, Blog and custom landing page. It's easy, fast and productive.

Aug 26, 2022

Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

slic Show Languages In Code. Usage Run it with an -h flag to list all commands. -d flag can be used to specify the directory of search -i flag can be

Dec 25, 2021

Generate an interactive, autocompleting shell for any Cobra CLI

Generate an interactive, autocompleting shell for any Cobra CLI

cobra-shell Description Leverages the Cobra completion API to generate an interactive shell for any Cobra CLI, powered by go-prompt. On-the-fly autoco

Dec 19, 2022
Comments
  • Exit with a return code for commands that return a boolean

    Exit with a return code for commands that return a boolean

    This return code indicates whether the command returned a "no" with a nonzero return code so you can use cidrchk in shell constructs like if and &&. This change also returns a return code of 1 when the user's command isn't found.

Github-org-diff - Simple CLI tool to check a diff between 2 branches of all org repos

github-org-diff Simple CLI tool to list org repos that have diff between dev and

Jan 25, 2022
cross-platform, cli app to perform various operations on string
cross-platform, cli app to perform various operations on string

sttr is command line software that allows you to quickly run various transformation operations on the string.

Dec 30, 2022
Vaku is a CLI and API for running path- and folder-based operations on the Vault Key/Value secrets engine.
Vaku is a CLI and API for running path- and folder-based operations on the Vault Key/Value secrets engine.

Vaku Vaku is a CLI and API for running path- and folder-based operations on the Vault Key/Value secrets engine. Vaku extends the existing Vault CLI an

Nov 28, 2022
The blackbean is a command tool for elasticsearch operations by using cobra.
The blackbean is a command tool for elasticsearch operations by using cobra.

The blackbean is a command tool for elasticsearch operations by using cobra. Besides, blackbean is the name of my lovely French bulldog.

Mar 3, 2022
Nebula Diagnosis CLI Tool is an information diagnosis cli tool for the nebula service and the node to which the service belongs.

Nebula Diagnosis CLI Tool is an information diagnosis cli tool for the nebula service and the node to which the service belongs.

Jan 12, 2022
A CLI Tool to easily generate your Terraform configuration

Tf Tf is a command line tool to easily generate your Terraform configuration with an interactive prompt. Inspiration Boredom in Covid-19 Installation

Sep 30, 2022
A tool to manage all your boilerplate from cli and generate files for you !

A tool to manage all your boilerplate from cli and generate files for you !

Jul 20, 2022
Cobra CLI tool to generate applications and commands

Cobra Generator Cobra provides its own program that will create your application and add any commands you want. It's the easiest way to incorporate Co

Jan 3, 2023
sttr is command line software that allows you to quickly run various transformation operations on the string.
sttr is command line software that allows you to quickly run various transformation operations on the string.

sttr is command line software that allows you to quickly run various transformation operations on the string.

Sep 21, 2021
A TUI multitool for day-to-day operations for software applications.

Bench (WIP) A TUI multitool for day-to-day operations for software applications. Lets you do common operations needed during IT work that are common e

Dec 5, 2021