Monday, May 7, 2012

IPV4 address format validation

This is a usual practice to validate a IPV4 address format read from a configuration file before consuming it. For this one should know what are all the valid IPV4 address formats.

1. IPV4 address consists of 32bits , i.e  in human readable format it is four octets devided by period ( dot)
 Here each octet takes value from 0-255 so the valid IPv4 adress ranges from to

2. The following formats are also valid

i.   8
     This address is treated as 32 bit integer so it is equal to

ii.   1.8
     In this format first octet is treated as first 8 bits and last octet is treated 24 bits. It is equal to

iii.   1.2.8
     In this format first two octets are treated as first 16bits and last octet is treated as next 16 bits of ip address. It is equal to

So, to validate any IPV4 address, one should consider all of the above valid IPV4 address formats.
Pin It
Related Posts Plugin for WordPress, Blogger...