【问题标题】:Incorrect results from geoLite2 IP databasegeoLite2 IP 数据库的结果不正确
【发布时间】:2014-12-01 19:11:48
【问题描述】:

使用最新的 GeoLite2 IP 数据库搜索 IP 54.73.154.147 我得到以下结果:

美国西雅图

但 IP 地址实际上来自在爱尔兰设立的 AWS 服务器。如果我向 GeoIP Precision 测试页面 (https://www.maxmind.com/en/geoip-demo) 提交相同的 IP,我会得到正确的结果:

都柏林,IE,爱尔兰

谁能想到为什么我会得到如此错误的结果?

【问题讨论】:

    标签: geolocation geoip maxmind


    【解决方案1】:

    您得到两个不同结果的原因是因为它们只是数据库的不同版本,而您在其网络界面上搜索的那个显然更准确和更新。 GeoLite2 不是很准确,您需要每周更新它以接收准确的信息,因为 IP 地址每分钟都在变化。例如,我购买了几个 IP 地址,我今天可以使用一个,明天可以随意转移到另一个。大公司这样做的频率更高,而且这些 IP 地址中的大多数都可以从一个国家转移到另一个国家。

    如果你只想坚持使用 MaxMind 产品,你可以使用这个 url 来请求 json:

    https://www.maxmind.com/geoip/v2.1/city/{{ip.address}}?use-downloadable-db=1&demo=1

    请注意,理论上一天只允许 25 个请求(但很容易破解)。不要问我如何破解它,因为它违反了 Stackoverflow 的规则。

    【讨论】:

      【解决方案2】:

      正如@michael 所指出的,如果 geolite 的数据库有误,您将无能为力。 这是另一种选择:userinfo.io。它实际上是几个数据库的合并,所以它可以更准确。

      我用你的 IP 对其进行了测试,它返回了正确的位置。

      {
        "ip_address": "54.73.154.147",
        "position": {
          "latitude": 53.3331,
          "longitude": -6.2489
        },
        "continent": {
          "name": "Europe",
          "code": "EU"
        },
        "country": {
          "name": "Ireland",
          "code": "IE"
        },
        "city": {
          "name": "Dublin"
        }
      }
      

      您目前可以使用javascript wrapperjava wrapper

      【讨论】:

      • userinfo.io 是一个很棒的网站。我也使用他们的服务。
      【解决方案3】:

      我遇到了完全相同的问题。我的 EC2 服务器在爱尔兰,但 geoip 显示的是美国。

      我切换到 freegeoip.net,这对于这种情况来说似乎是准确的。

      PHP中的使用示例:

      $json_data = file_get_contents("http://freegeoip.net/json/" . $hostname);
      return json_decode($json_data, TRUE);
      

      【讨论】:

        【解决方案4】:

        此脚本将解决您的问题。 我用你的IP地址测试过,结果是正确的

        <?php
            /*Get user ip address*/
            //$ip_address=$_SERVER['REMOTE_ADDR'];
            $ip_address="54.73.154.147";
            /*Get user ip address details with geoplugin.net*/
            $geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address;
            $addrDetailsArr = unserialize(file_get_contents($geopluginURL)); 
        
        
            /*Get City name by return array*/ 
            $city = $addrDetailsArr['geoplugin_city']; 
        
            /*Get Country name by return array*/ 
            $country = $addrDetailsArr['geoplugin_countryName'];
        
            $latitude = $addrDetailsArr['geoplugin_latitude'];
        
            $logitude = $addrDetailsArr['geoplugin_longitude'];
            /*Comment out these line to see all the posible details*/
            /*echo '<pre>'; 
            print_r($addrDetailsArr);
            die();*/
        
            if(!$city){
                $city='Not Define'; 
            }if(!$country){
                $country='Not Define'; 
            }
            echo '<strong>IP Address</strong>:- '.$ip_address.'<br/>';
            echo '<strong>City</strong>:- '.$city.'<br/>';
            echo '<strong>Country</strong>:- '.$country.'<br/>';
            echo '<strong>Latitude</strong>:- '.$latitude.'<br/>';
            echo '<strong>Longitude</strong>:- '.$logitude.'<br/>';
        ?>  
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-12-07
          • 1970-01-01
          • 2010-11-14
          • 2019-05-31
          • 1970-01-01
          • 1970-01-01
          • 2017-06-12
          • 1970-01-01
          相关资源
          最近更新 更多