2014-10-07 96 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