Maxmind Geolitecity数据库中的IP地址表示 [英] IP address representation in the Maxmind Geolitecity database
问题描述
我在Mysql数据库中有Maxmind Geolitecity数据库.
I have the Maxmind Geolitecity database in a Mysql database.
我可以看到类似startIpNum
和endIpNum
的字段.
I could see field like startIpNum
and endIpNum
.
这些字段的值如下:startIpNum
为16777216,endIpNum为16777471
.
The values for those fields are like this: 16777216 for startIpNum
and 16777471
for endIpNum`.
我的IP是115.184.126.186,如何转换我的IP以匹配startIpNum
或endIpNum
?
My ip is 115.184.126.186, how can I convert my ip to match the startIpNum
or endIpNum
?
推荐答案
要么按照lmz的建议使用inet_aton(),要么在php中使用以下方法:
Either use inet_aton() as suggested by lmz, or do it in php using:
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) )
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)
这篇关于Maxmind Geolitecity数据库中的IP地址表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!