从远程脚本获取用户IP

时间:2016-05-19 11:30:02

标签: javascript api remote-access

我有一个从远程位置加载脚本的页面(例如myscript.com

此脚本向远程API发出Ajax请求。

此API如何获取访问者的IP地址?

如果我在请求处理程序中使用request.remote_addr,我会从脚本的位置(myscript.com)获取IP。

1 个答案:

答案 0 :(得分: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!