IP Number

The IP_FROM and IP_TO fields of the IP-to-Country Database are numeric representations of the dotted IP address.


The formula to convert an IP Address of the form A.B.C.D to an IP Number is:
IP Number = A x (256*256*256) + B x (256*256) + C x 256 + D
Which is the same as:
IP Number = A x 16777216 + B x 65536 + C x 256 + D


In PHP 4 you can use the following to convert a dotted IP Address to its corresponding IP Number:
$ip_number = sprintf("%u", ip2long($dotted_ip_address));

and this to convert IP Number to its corresponding dotted IP Address:
$dotted_ip_address = long2ip($ip_number);