问题
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 16777471
for 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