获取ip地址

来源:互联网 发布:linux c 串口中断 编辑:程序博客网 时间:2024/06/04 17:26



//js获取ip地址
get_ip(function (info) {
console.log(info)
     var str=info.country + info.province + info.city;
     $('body').html(str);
});
function get_ip(cb) {
     var script = document.createElement("script"),
         s  = document.getElementsByTagName("script")[0];
           
    script.src = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=jsonp";
    s.parentNode.insertBefore(script, s);
    
    var it = setInterval(function () {
        if (!!remote_ip_info) {
            cb(remote_ip_info);
            remote_ip_info = null;
            
            clearInterval(it);
            it = null;
        }
    }, 100);
}

0 0