Javascript:检测真实的IP地址 [英] Javascript : detect real IP address

查看:472
本文介绍了Javascript:检测真实的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用EasyJQuery使用以下脚本检测用户的IP地址和其他信息:

I was using "EasyJQuery" to detect the user's IP address and other information using the script below :

<!-- Require jQuery / Anyversion --><script type="text/javascript" language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- Require EasyJQuery After JQuery --><script type="text/javascript" language="Javascript" src="http://api.easyjquery.com/easyjquery.js"></script>
<script type="text/javascript" language="Javascript">
    // 1. Your Data Here
    function my_callback(json) {
        alert("IP :" + json.IP + " nCOUNTRY: " + json.COUNTRY);
    }

    function my_callback2(json) {
        // more information at http://api.easyjquery.com/test/demo-ip.php
        alert("IP :" + json.IP + " nCOUNTRY: " + json.COUNTRY + " City: " + json.cityName + " regionName: " + json.regionName);
    }

    // 2. Setup Callback Function
   // EasyjQuery_Get_IP("my_callback"); // fastest version
    EasyjQuery_Get_IP("my_callback2","full"); // full version
</script>

现在它不再有用了。官方页面现在重定向到: ip.codehelper.io ,Github库只有PHP版本而不是Javascript one。

Now it's no more working. The official page is now redirecting to :ip.codehelper.io and the Github library has only a PHP version not a Javascript one.

那么这个库真的不再受支持吗?如果是,是否有类似的?

So is this library really no longer supported? If yes, is there a similar one?

提前谢谢。

推荐答案

从您链接的页面to:

// First, embed this script in your head or at bottom of the page.
<script src="http://www.codehelper.io/api/ips/?js"></script>
// You can use it
<script>
    alert(codehelper_ip.IP);
    alert(codehelper_ip.Country);
</script>

这样的事情可能会更好:

Or something like this might be better:

$.getJSON('http://www.codehelper.io/api/ips/?js&callback=?', function(response) {
    console.log(response.IP, response.Country, response.CityName);
})

这篇关于Javascript:检测真实的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆