我在Mysql数据库中拥有Maxmind Geolitecity数据库。Maxmind Geolitecity数据库中的IP地址表示
我可以看到像startIpNum
和endIpNum
的字段。
这些字段的值如下所示:16777216代表startIpNum
和16777471
代表endIpNum`。
我的ip是115.184.126.186,我该如何转换我的IP来匹配startIpNum
或endIpNum
?
我在Mysql数据库中拥有Maxmind Geolitecity数据库。Maxmind Geolitecity数据库中的IP地址表示
我可以看到像startIpNum
和endIpNum
的字段。
这些字段的值如下所示:16777216代表startIpNum
和16777471
代表endIpNum`。
我的ip是115.184.126.186,我该如何转换我的IP来匹配startIpNum
或endIpNum
?
尝试MySQL中的inet_aton
函数。
尝试这样的事:
<?php
$ipadd="115.184.126.186";
$ips = explode(".",$ipadd);
$x=($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
echo $x;
?>
只是修改此一进一出功能..
here是代码
的结果要么使用INET_ATON()由两面针的建议,或者在php中使用:
http://php.net/manual/en/function.ip2long.php
请注意,这个函数返回一个有符号的整数,意思是范围从-2,147,483,648到2,147,483,647,我认为maxmind geoip数据库使用无符号整数(0-4,294,967,295?),因此您需要向它添加2,147,483,647(2^31-1)
尝试将它像这个 -
SELECT INET_ATON("115.184.126.186");
我的pritty确保您可以用sprintf( “%U”,$ ip2long($ IP)),以获得在PHP long int类型的无符号表示。 – WASD42
也许,如果你想要一个字符串表示(这将在SQL连接的情况下)的作品。 – jishi