Crea sito

Posts tagged english

Sort IP Addresses with GNU sort


On UNIX like operating systems, an IP address can be sorted using the utility sort, part of the GNU Core utils

 sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4

-n, –numeric-sort          compare according to string numerical value

-t, –field-separator=SEP  use SEP instead of non-blank to blank transition

-k, –key=POS1[,POS2] start a key at POS1 (origin 1), end it at POS2

If you like a well written explanation of this, I invite you to read this article by Paul Heinlein.

Network notes.


Partially taken from


Internet Protocol and the Transmission Control Protocol.

IP address is a 32-bit logical number to address a network device. IP are normally represented by decimal numbers, but could be useful sometimes to represent them in binary.

172. 19. 88. 73

An IP address is divided in 4 parts (each 8 bits), these parts are called octets. In the IPV4 there are 5 address classes:

Class A from 1 to 126, in binary the octet start with 0xxx
127 Reserved for loopback, 01111111
Class B from 128 to 191, in binary the octet start with 10xx
Class C from 192 to 223, in binary the octet start with 110x
Class D from 224 to 239, in binary the octet start with 1110 Don’t use. Reserved for the future.
Class E from 240 to 254, in binary the octet start with 1111

IANA reserved 4 address ranges to be used in private networks, these addresses won’t appear on the Internet avoiding IP address conflicts.,, and that means:

– through
– through
– through
– through (reserved for Automatic Private IP Addressing)

The meaning of 8,12 and 16 is

8 =
12 =
16 =

These are subnet mask.

A subnet mask is used to determine which part is the network (n) part and which is the host (H) part.
Default subnet masks:
Class B that is nnnnnnnn.nnnnnnnn.HHHHHHHH.HHHHHHHH
Class C that is nnnnnnnn.nnnnnnnn.nnnnnnnn.HHHHHHHH


Bitwise (logical AND) between IP address and subnet mask to have the IP of the network


To calculate how many subnet in a net mask I can have use the formula (2^n) -2 where n is the number of bits in either field. For example the subnet (11111111.11111111.11110000.00000000 could have (2^4) – 2 = 14 subnets.


Go to Top