2016-05-19 58 views
0

我有它加載從遠程位置(腳本說myscript.com獲取用戶IP

這個腳本一個Ajax請求到一個遙遠的API。

頁這個API如何獲得訪問者的IP地址?

如果我在請求處理程序使用request.remote_addr,我從腳本的位置(myscript.com)的IP。

+0

您是否考慮過將訪問者的IP作爲腳本參數運行遠程腳本? – Will

+0

@William我知道這種可能性,但想避免它,因爲它會延遲Ajax調用(不得不等待遠程專用IP API響應) – Jivan

回答

1

使用此API來獲取所有這些數據作爲誰訪問了您的網頁JSON
{"as":"AS9583SifyLimited","city":"Bengaluru","country":"India","countryCode":"IN","isp":"Sify Limited","lat":12.9833,"lon":77.5833,"org":"Sify Limited","query":"202.191.210.194","region":"KA","regionName":"Karnataka","status":"success","timezone":"Asia/Kolkata","zip":"560099"}

API_Location=' http://ip-api.com/json'; 
      $.getJSON(API_Location) 
       .done(function(position) { 
        if (position.lat && position.lon) { 
        updateWeather(position); 
       } else { 
        updateWeather({"lat":DEFAULT_LAT, "lon":DEFAULT_LON}); 
       } 
       }) 
       .fail(function(jqxhr, textStatus, error) { 
       var err = textStatus + ", " + error; 
       console.log("Request Failed: " + err); 
      }); 

訪問此頁ip,你可以得到如何獲得IP!