2014-10-07 110 views
1

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

美国西雅图,美国

但IP地址实际上是从AWS服务器在爱尔兰兴起。如果我提交相同IP的GeoIP的精密测试页(https://www.maxmind.com/en/geoip-demo)我得到正确的结果:

都柏林,IE,爱尔兰

任何人都可以想出一个理由,为什么即时得到这样的错误的结果?

回答

2

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

如果你只是想坚持的MaxMind的产品,你可以使用这个URL请求JSON:

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

请注意,只有25个请求是允许在理论(但容易被破解)的日子。不要问我如何破解它,因为它违反了Stackoverflow的规则。

-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/>'; 
?> 
1

正如@迈克尔指出,你不能,如果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

+1

userinfo.io是一个很棒的网站。我也使用他们的服务。 – 2015-03-26 00:58:17