【问题标题】:How do i find the geographical co-ordinates/locations of a server?我如何找到服务器的地理坐标/位置?
【发布时间】:2013-01-25 06:37:44
【问题描述】:

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

【问题讨论】:

    标签: mysql networking geography


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      在 python 中使用 pygeoip :

      #!/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()
      

      您下载Geo city database 并以此格式创建MyIpList.txt 文件。

      64.233.161.99
      209.131.36.159
      

      这个脚本打印: 国家代码 国家代码3 国家的名字 地区/城市 邮政编码 纬度 经度 dma_code 地铁代码 区号 区域名称 时区

      record_by_addr() 返回一个字典。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-13
        • 1970-01-01
        • 2015-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多