Handbook
IP Number
Last updated by amit on Thu, 09/25/2003 - 01:25
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:
In PHP 4 you can use the following to convert a dotted IP Address to its corresponding IP Number:
and this to convert IP Number to its corresponding 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 + DWhich 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);
