Skip to content

flowchartsman/cidr-convert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

CIDR block calculator.

Takes a set of dotted-quad IP addresses, ranges, or CIDR blocks, on
 stdin; at EOF, prints a minimal set of CIDR ranges to stdout.

Input consists of a stream of dotted-quads, pairs of dotted-quads
 separated by a dash, or dotted-quads with /number widths after
 them.  Dash-separated ranges refer to all addresses between the
 two, inclusive; an address with a /number after it refers to a
 CIDR-style block.  It is not an error for an address to be
 specified in the input more than once.  Whitespace may appear
 anywhere except within a dotted-quad or CIDR width.  Characters
 other than digits, dots, dashes, and whitespace are errors.  If a
 number in a dotted-quad is greater than 255, or a CIDR width is
 greater than 32, or other syntax errors occur (such as too many
 dots without whitespace, dash, or slash) a complaint is printed and
 the dotted-quad, range, or block in which it appears is skipped.

Output consists of zero or more lines, each a dotted-quad/width CIDR
 net-with-mask, including all and only the addresses in the input.
 It will be a minimal set, in that no two blocks in the output can
 be collapsed without resorting to noncontiguous netmasks.

Compile-time options:

     -DNO_PROGNAME
             Provide __progname, for systems that don't have it.  If
             it shows up undefined at link time, try compiling with
             this turned on.

This file is in the public domain.

Originally obtained from: http://www.spamshield.org/cidr-convert.c 

Added to github on 02-01-2012 initially to fix a simple display bug for initial
quads over 127.  The goal is to allow for collaborative tweaking and development
of this useful tool.

As of 05-27-2015, I have ported the tool to Go as well. Mostly as a learning
exercise. Build with 'go build cidr-convert.go' to prevent the compiler from
getting confused.

About

Convert a list of IP addresses/ranges to their minimized cidr form

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published