js获取ie客户端ip与mac地址

发布时间:2019-11-08编辑:脚本学堂
用js获取客户端ip与mac地址,js取客户端ip的实例代码,有需要的朋友参考下。

例子,用js脚本获取客户端的IP地址与mac物理地址。
 

复制代码 代码示例:
<html><head>
<title>wmi客户端ip_www.jb200.com</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);
 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.instancesofasync(foo, 'win32_networkadapterconfiguration');
   </script>
<form id=formfoo name=formbar action=nicpost.asp method=post><input value=00:05:5d:0e:c7:fa name=txtmacaddr> <input value=192.168.0.2 name=txtipaddr> <input value=typ name=txtdnsname> </form></body></html>

关键是用到两个activex:
 

<object id=locator classid=clsid:76a64158-cb41-11d1-8b02-00600806d9b6 viewastext></object>
<object id=foo classid=clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223></object>

不过这两个activex都是系统自带,不用去下载或注册。

然后就是用脚本和activex交互,脚本可以是js或vbs。

js获取客户端ip实例解析
Js获取客户端IP地址与MAC地址
JS获取客户端IP地址与机器名示例