1

我有一个包含 190 个 IP 地址列表的文本文件。我如何获得所有这些服务器的位置?

4

2 回答 2

1

在带有 pygeoip 的 python 中:

#!/usr/bin/env python
import sys
import pygeoip

def main():
    db = pygeoip.GeoIP('GeoLiteCity.dat')
    source = "MyIpList.txt"
    with open(source, 'r') as fs:
        lignes = fs.readlines()
        for ip in lignes:
            dico =  db.record_by_addr(ip)
            for k,v in dico.iteritems():
                print "%s : %s" % (k,v)

if __name__ == '__main__':
    main()

您下载地理城市数据库并以此格式创建 MyIpList.txt 文件。

64.233.161.99
209.131.36.159

此脚本打印: country_code country_code3 country_name region, city postal_code latitude longitude dma_code metro_code area_code region_name time_zone

record_by_addr()返回一个字典。

于 2013-01-26T23:15:27.420 回答
1

有一些免费的 IP 到地理位置 API,例如ipinfodb,在页面下方有一些不同语言的示例。我建议在谷歌上搜索“ip to location api”一词以获取更多 api。

于 2013-01-25T06:57:00.957 回答