IP address representation in the Maxmind Geolitecity database

走远了吗. 提交于 2019-12-11 04:29:45

问题


I have the Maxmind Geolitecity database in a Mysql database.

I could see field like startIpNum and endIpNum.

The values for those fields are like this: 16777216 for startIpNum and 16777471for endIpNum`.

My ip is 115.184.126.186, how can I convert my ip to match the startIpNum or endIpNum?


回答1:


Either use inet_aton() as suggested by lmz, or do it in php using:

http://php.net/manual/en/function.ip2long.php

Note that this function returns an signed integer, meaning ranging from − 2,147,483,648 to 2,147,483,647, and I think the maxmind geoip database uses unsigned ints (0-4,294,967,295?) so you need to add 2,147,483,647 to it (2^31-1)




回答2:


Try the inet_aton function in MySQL.




回答3:


try something like this :

<?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;
?>

just modify this one into a function..

here is the result of the code




回答4:


Try converting it like this-

SELECT INET_ATON("115.184.126.186");



来源:https://stackoverflow.com/questions/6608120/ip-address-representation-in-the-maxmind-geolitecity-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!