寻找WIN7下通过JS获取本机IP的方法
原来在XP上能通过获取到IP,但是到了WIN7上就不行了,原来的获取方法:
<script language="JavaScript">
function GetLocalIPAddr(){
var oSetting = null;
var ip = null;
try{
oSetting = new ActiveXObject("rcbdyctl.Setting");
ip = oSetting.GetIPAddress;
alert(ip);
if (ip.length == 0){
return "没有连接到Internet";
}
oSetting = null;
}catch(e){
return ip;
}
return ip;
}
alert(GetLocalIPAddr())
</script>
在网上找了一下其他获取IP的方法
这个直接通过Js来执行ipconfig命令获取IP,但是安全性能是不是较低啊
http://topic.csdn.net/t/20041010/12/3440117.html
这个是通过ActiveX控件来获取的
http://blog.csdn.net/nwf5d/archive/2010/06/29/5702581.aspx
<HTML><HEAD><TITLE>WMI Scripting HTML</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT language=JScript event="OnCompleted(hResult,pErrorObject, pAsyncContext)" for=foo>
// document.forms[0].txtMACAddr.value=unescape(MACAddr);
document.forms[0].txtIPAddr.value=unescape(IPAddr);
alert(unescape(IPAddr));
// document.forms[0].txtDNSName.value=unescape(sDNSName);
//document.formbar.submit();
</SCRIPT>
<SCRIPT language=JScript event=OnObjectReady(objObject,objAsyncContext) for=foo>
if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true)
{
//if(objObject.MACAddress != null && objObject.MACAddress != "undefined")
//MACAddr = objObject.MACAddress;
if(objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined")
IPAddr = objObject.IPAddress(0);
//if(objObject.DNSHostName != null && objObject.DNSHostName != "undefined")
//sDNSName = objObject.DNSHostName;
}
</SCRIPT>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY>
<OBJECT id=locator classid=CLSID:76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT></OBJECT>
<OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223></OBJECT>
<SCRIPT language=JScript>
var service = locator.ConnectServer();
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
service.Security_.ImpersonationLevel=3;
service.Inst