geoLite2 IP数据库的结果不正确

时间:2014-10-07 11:09:47

标签: geolocation geoip maxmind

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

美国西雅图,美国

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

都柏林,IE,爱尔兰

任何人都可以想到为什么我会得到这样的错误结果?

4 个答案:

答案 0 :(得分:3)

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

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

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

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

答案 1 :(得分:1)

正如@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

答案 2 :(得分:0)

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

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

PHP中的使用示例:

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

答案 3 :(得分:-1)

此脚本将解决您的问题。 我用你的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/>';
?>  
相关问题