Выдержка с http_://ip-to-country.webhosting.info/node/view/55 :
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);
Пример:
172.16.0.1 = 2885681152+1048576+0+1 = 2886729729 - 2886729736
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);
Пример:
172.16.0.1 = 2885681152+1048576+0+1 = 2886729729 - 2886729736