Sunday, December 25, 2011

Network subnet mask IP address calculator

One of the task installing a new FreeBSD box was dealing with IP addresses. Usually, google a web based calculator would do the trick. But today's task is a bit different.

IPv6. A whole row of hexadecimal spinning in front of my eyes, just to figure out what is the range of IP that is usable. Web based IP calculator (based on java script) are not accessible using console based internet browser (links & lynx).

Spontaneously, searching the apt repository return some very interesting stuff.

Console based IP calculatorsipcalc.

Not only it is intelligent enough to figure out the input but also it is intelligent enough to generate useful output. Surprisingly, the output is scripting friendly (using grep and sed will parse the output).

These are the steps to install it under FreeBSD & Debian based distribution (e.g. Ubuntu) :

In FreeBSD :
cd /usr/ports/net-mgmt/sipcalc/;make install clean

In Debian based distribution :
apt-get install sipcalc


Usage example :
Just run the sipcalc follow by ip address and netmask
#sipcalc 192.168.0.0 255.255.252.0
-[ipv4 : 192.168.0.0 255.255.252.0] - 0

[CIDR]
Host address            - 192.168.0.0
Host address (decimal)  - 3232235520
Host address (hex)      - C0A80000
Network address         - 192.168.0.0
Network mask            - 255.255.252.0
Network mask (bits)     - 22
Network mask (hex)      - FFFFFC00
Broadcast address       - 192.168.3.255
Cisco wildcard          - 0.0.3.255
Addresses in network    - 1024
Network range           - 192.168.0.0 - 192.168.3.255
Usable range            - 192.168.0.1 - 192.168.3.254

Or CIDR (Classless Inter-Domain Routing) notation IP address
#sipcalc 192.168.0.0/22
-[ipv4 : 192.168.0.0/22] - 0

[CIDR]
Host address            - 192.168.0.0
Host address (decimal)  - 3232235520
Host address (hex)      - C0A80000
Network address         - 192.168.0.0
Network mask            - 255.255.252.0
Network mask (bits)     - 22
Network mask (hex)      - FFFFFC00
Broadcast address       - 192.168.3.255
Cisco wildcard          - 0.0.3.255
Addresses in network    - 1024
Network range           - 192.168.0.0 - 192.168.3.255
Usable range            - 192.168.0.1 - 192.168.3.254

For a more detail output, add the parameter "-a" to sipcalc. e.g.
#sipcalc -a 192.168.0.1/28
-[ipv4 : 192.168.0.1/28] - 0

[Classfull]
Host address            - 192.168.0.1
Host address (decimal)  - 3232235521
Host address (hex)      - C0A80001
Network address         - 192.168.0.0
Network class           - C
Network mask            - 255.255.255.0
Network mask (hex)      - FFFFFF00
Broadcast address       - 192.168.0.255

[CIDR]
Host address            - 192.168.0.1
Host address (decimal)  - 3232235521
Host address (hex)      - C0A80001
Network address         - 192.168.0.0
Network mask            - 255.255.255.240
Network mask (bits)     - 28
Network mask (hex)      - FFFFFFF0
Broadcast address       - 192.168.0.15
Cisco wildcard          - 0.0.0.15
Addresses in network    - 16
Network range           - 192.168.0.0 - 192.168.0.15
Usable range            - 192.168.0.1 - 192.168.0.14

[Classfull bitmaps]
Network address         - 11000000.10101000.00000000.00000000
Network mask            - 11111111.11111111.11111111.00000000

[CIDR bitmaps]
Host address            - 11000000.10101000.00000000.00000001
Network address         - 11000000.10101000.00000000.00000000
Network mask            - 11111111.11111111.11111111.11110000
Broadcast address       - 11000000.10101000.00000000.00001111
Cisco wildcard          - 00000000.00000000.00000000.00001111
Network range           - 11000000.10101000.00000000.00000000 -
11000000.10101000.00000000.00001111
Usable range            - 11000000.10101000.00000000.00000001 -
11000000.10101000.00000000.00001110

[Networks]
Network                 - 192.168.0.0     - 192.168.0.15 (current)
Network                 - 192.168.0.16    - 192.168.0.31
Network                 - 192.168.0.32    - 192.168.0.47
Network                 - 192.168.0.48    - 192.168.0.63
Network                 - 192.168.0.64    - 192.168.0.79
Network                 - 192.168.0.80    - 192.168.0.95
Network                 - 192.168.0.96    - 192.168.0.111
Network                 - 192.168.0.112   - 192.168.0.127
Network                 - 192.168.0.128   - 192.168.0.143
Network                 - 192.168.0.144   - 192.168.0.159
Network                 - 192.168.0.160   - 192.168.0.175
Network                 - 192.168.0.176   - 192.168.0.191
Network                 - 192.168.0.192   - 192.168.0.207
Network                 - 192.168.0.208   - 192.168.0.223
Network                 - 192.168.0.224   - 192.168.0.239
Network                 - 192.168.0.240   - 192.168.0.255


As for IPv6, below are the sample usage :
#sipcalc 1111:2222:3333:4444:5555:6666:7777:8888/112
-[ipv6 : 1111:2222:3333:4444:5555:6666:7777:8888/112] - 0

[IPV6 INFO]
Expanded Address        - 1111:2222:3333:4444:5555:6666:7777:8888
Compressed address      - 1111:2222:3333:4444:5555:6666:7777:8888
Subnet prefix (masked)  - 1111:2222:3333:4444:5555:6666:7777:0/112
Address ID (masked)     - 0:0:0:0:0:0:0:8888/112
Prefix address          - ffff:ffff:ffff:ffff:ffff:ffff:ffff:0
Prefix length           - 112
Address type            - Unassigned
Network range           - 1111:2222:3333:4444:5555:6666:7777:0000 -
1111:2222:3333:4444:5555:6666:7777:ffff

As like IPv4, adding the parameter "-a" would yield a more verbose output.

Namaste !!!

Reference:
http://scratching.psybermonkey.net/2009/09/network-ip-address-calculator-for.html

No comments: