如何使用GeoLite City,如何获取startIpNum和endIpNum

How to use GeoLite City, how to obtain startIpNum and endIpNum

好的,我从 http://dev.maxmind.com/geoip/legacy/geolite/ GeoLite City 数据库下载。

值在 GeoLiteCity-Blocks.csv

startIpNum,endIpNum,locId
"16777216","16777471","17"

但是我不知道如何将 ips 转换为这些 startIpNum 和 endIpNum 范围。我在他们的网站上找不到,他们 link 到这里

ip v4 转换成这个的算法是什么?

非常感谢

这取决于您使用哪种编程语言。

在php中,您可以使用ip2long和long2ip来处理ips。

string long2ip ( string $proper_address )
The function long2ip() generates an Internet address in dotted format (i.e.: aaa.bbb.ccc.ddd) from the proper address representation.

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

您提供的 ip 示例:http://sandbox.onlinephpfunctions.com/code/3decd3d4818a02d65b9a80cf2dc1c70297b0d2d5

如果您使用的是 Python,则可以使用

>>> import socket, struct
>>> socket.inet_ntoa(struct.pack('!L', 16777216))
'1.0.0.0'

从整数转换为 IP 字符串。