var wwip=\"\";
$(function(){
$(document).ready( function() {
$.getJSON( \"http://smart-ip.net/geoip-json?callback=?\",
function(data){
alert( data.host);
wwip=data.host;
}
);
});
});
这个问题查了很多资料,都不可以,这个还好用。
例子,js获取本地与外网IP地址。
<script language=\"javascript\" type=\"text/javascript\">
//获取本地IP
function GetLocalIPAddress()
{
var obj = null;
var rslt = \"\";
try
{
obj = new ActiveXObject(\"rcbdyctl.Setting\");
rslt = obj.GetIPAddress;
obj = null;
}
catch(e)
{
alert(\"ErrInfoIS:\"+e)
}
return rslt;
}
document.write(\"你的IP是:\" + GetLocalIPAddress());
</script>
以上是js获取本地ip地址的方法,下面来看js获取外网ip地址的例子。
<script language=\"javascript\"> //获取外网IP xml=new ActiveXObject(\"Microsoft.XMLHTTP\"); xml.open(\"GET\",\"http://city.ip138.com/city0.asp\",false); xml.send(); kk=xml.ResponseText; i=kk.indexOf(\"[\"); ie=kk.indexOf(\"]\"); ip=kk.substring(i+1,ie); document.write(\"<span style=\'color:red;font-size:12;\' cursor=\'hand\'>您的IP地址是:\" + ip + \"</span>\"); </script>
本文地址:https://www.stayed.cn/item/6055
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我