Subnet calculator - command line tool to calculate from a given IP address possible CIDR network/mask and address ranges

Usage: subnet-calc IP-address/[number-of-bits]
or: subnet-calc IP-address [number-of-bits]
e.g.
subnet-calc 192.168.0.1/24
will produce:
192.168.0.0/24 = 192.168.0.1 - 192.168.0.255
and
subnet-calc 192.168.0.1
will produce:
192.0.0.0/8 = 192.0.0.0 - 192.255.255.255
192.128.0.0/9 = 192.128.0.0 - 192.255.255.255
192.128.0.0/10 = 192.128.0.0 - 192.191.255.255
192.160.0.0/11 = 192.160.0.0 - 192.191.255.255
192.160.0.0/12 = 192.160.0.0 - 192.175.255.255
192.168.0.0/13 = 192.168.0.0 - 192.175.255.255
192.168.0.0/14 = 192.168.0.0 - 192.171.255.255
192.168.0.0/15 = 192.168.0.0 - 192.169.255.255
192.168.0.0/16 = 192.168.0.0 - 192.168.255.255
192.168.0.0/17 = 192.168.0.0 - 192.168.127.255
192.168.0.0/18 = 192.168.0.0 - 192.168.63.255
192.168.0.0/19 = 192.168.0.0 - 192.168.31.255
192.168.0.0/20 = 192.168.0.0 - 192.168.15.255
192.168.0.0/21 = 192.168.0.0 - 192.168.7.255
192.168.0.0/22 = 192.168.0.0 - 192.168.3.255
192.168.0.0/23 = 192.168.0.0 - 192.168.1.255
192.168.0.0/24 = 192.168.0.0 - 192.168.0.255
192.168.0.0/25 = 192.168.0.0 - 192.168.0.127
192.168.0.0/26 = 192.168.0.0 - 192.168.0.63
192.168.0.0/27 = 192.168.0.0 - 192.168.0.31
192.168.0.0/28 = 192.168.0.0 - 192.168.0.15
192.168.0.0/29 = 192.168.0.0 - 192.168.0.7
192.168.0.0/30 = 192.168.0.0 - 192.168.0.3

It skips masks 1-7 and 31-32 bits long as these are less useful.

Zip file containing source, read-me and MacOS X binary is here. Unzip and copy to /usr/local/bin (or somewhere else).

Source is here. To compile: g++ subnet-calc.c -o subnet-calc

This is free software. I hope you will find it useful.