javascript 通过IE ActiveX 获得本机内网ip
<HTML><HEAD><TITLE>WMI Scripting HTML</TITLE> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <script type="text/javascript"> function GetAdapterInfo() { var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); var service = locator.ConnectServer("."); //连接本机服务器 var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=TRUE"); //查询使用SQL标准 var e = new Enumerator (properties); var msg=""; for (;!e.atEnd();e.moveNext ()) { var p = e.item (); msg+="Caption:" + p.Caption + " "; //网卡描述,也可以使用Description msg+="IP:" + p.IPAddress(0) + " ";//IP地址为数组类型,子网俺码及默认网关亦同 msg+="MAC:" + p.MACAddress + " "; //网卡物理地址 } return msg; } alert( GetAdapterInfo()); </script> <BODY> </BODY> </HTML>
作者:冯际成
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利.如有问题,请与作者联系:604756218@qq.com