GURI SoftHouse
System Development,
Auditing and Consulting

IP4RANGE2CIDR


ip4range2cidr is a utility to calculate CIDR blocks (network address and netmask) from a range of IP addresses.

EXAMPLE OF USE:

Some applications do not provide configuration capabilities using IP range, but only CIDR. Example: POSTFIX.

Assuming it is necessary to lock the following range of IP addresses:

192.168.0.128 até 192.168.255.255.

Doing this "by hand", and per block, you would write 256 blocks CIDR. With the ip4range2cidr, the result is:

[utvg@torrinha ip4range2cidr]$ ./ip4range2cidr 192.168.0.128 192.168.255.255
NETWORK=192.168.0.128 / NETMASK=25 or 255.255.255.128 / BROADCAST=192.168.0.255
NETWORK=192.168.1.0 / NETMASK=24 or 255.255.255.0 / BROADCAST=192.168.1.255
NETWORK=192.168.2.0 / NETMASK=23 or 255.255.254.0 / BROADCAST=192.168.3.255
NETWORK=192.168.4.0 / NETMASK=22 or 255.255.252.0 / BROADCAST=192.168.7.255
NETWORK=192.168.8.0 / NETMASK=21 or 255.255.248.0 / BROADCAST=192.168.15.255
NETWORK=192.168.16.0 / NETMASK=20 or 255.255.240.0 / BROADCAST=192.168.31.255
NETWORK=192.168.32.0 / NETMASK=19 or 255.255.224.0 / BROADCAST=192.168.63.255
NETWORK=192.168.64.0 / NETMASK=18 or 255.255.192.0 / BROADCAST=192.168.127.255
NETWORK=192.168.128.0 / NETMASK=17 or 255.255.128.0 / BROADCAST=192.168.255.255
[utvg@torrinha ip4range2cidr]$

The same application can be used to operate internally of a CGI. You can also use the code in javascript, but it contains some limitations. I invite you to teste the script.

The license is GPL-3. The source code of the test page and the application are compressed in IP4range2CIDR-src.tar.gz

To compile the code you will need GCC compiler.

[utvg@torrinha ip4range2cidr]$ make clean
rm -f ip4range2cidr.o ip4range2cidr
[utvg@torrinha ip4range2cidr]$ make
gcc -s -O3 ip4range2cidr.c -o ip4range2cidr

Because it is an administrative tool then the binary runs in text mode (console), as already shown previously.

USING THE HTML VERSION

The tar.gz file also contains the html file and a small javascript library (MandaBala.js) with functions needed by converter. HTML+Javascript version can run on any system with browser with JavaScript capable and enabled.

As mentioned, the version HTML+Javascript has limitations due the JavaScript language, but I believe that it will meet most "normal" conditions. However, in exceptional cases (for academic study, of course!) then you can call a CGI script to avoid the limitation.

Comments and suggestions are welcome. Contact GURI!