Javascript:检测真实的IP地址

时间:2013-09-26 19:38:09

标签: javascript ip

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

<!-- 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版本。

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

提前谢谢。

2 个答案:

答案 0 :(得分:3)

从您关联的页面:

// 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>

或者类似的东西可能会更好:

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

答案 1 :(得分:1)

$.ajax({ 
            url: '//freegeoip.net/json/', 
            type: 'POST', 
            dataType: 'jsonp',
            success: function(location) {
               console.log(location);
              }
        });