javascript获取本地及外网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>


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

你可能感兴趣的:(javascript获取本地及外网IP地址)