欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JScript中调用ActiveX获取访客网卡MAC地址实现代码

程序员文章站 2022-07-02 18:18:23
jscript调用activexobject获取访客的网卡mac地址,注意只能ie下运行(ie8+没测试),会有安全提示,提示如下: 复制代码 代码如下: 在此页上的a...

jscript调用activexobject获取访客的网卡mac地址,注意只能ie下运行(ie8+没测试),会有安全提示,提示如下:

复制代码 代码如下:

在此页上的activex控件和本页上的其他部分的交互可能不安全。你想允许这种交互吗?

JScript中调用ActiveX获取访客网卡MAC地址实现代码

注意选择”是“,要不报错无法获取:

JScript中调用ActiveX获取访客网卡MAC地址实现代码

源代码如下:

<html> 
<head> 
<title>jscript+activex获取访客mac网卡地址</title> 
</head> 
<body> 
<object classid="clsid:76a64158-cb41-11d1-8b02-00600806d9b6" id="locator" style="display:none;visibility:hidden"></object> 
<object classid="clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223" id="foo" style="display:none;visibility:hidden"></object> 
<form name="myform"> 
<br/>mac地址:<input type="text" name="macaddress"> 
<br/>ip地址:<input type="text" name="ipaddress"> 
<br/>主机名:<input type="text" name="hostname"> 
</form> 
</body> 
</html>
<script language="javascript">
    var smacaddr = "";
    var sipaddr = "";
    var sdnsname = "";
    var service = locator.connectserver();
    service.security_.impersonationlevel = 3;
    service.instancesofasync(foo, 'win32_networkadapterconfiguration'); 
  </script> 
<script for="foo" event="onobjectready(objobject,objasynccontext)" language="jscript"> 
       if(objobject.ipenabled != null && objobject.ipenabled != "undefined" && objobject.ipenabled == true){ 
                if(objobject.ipenabled && objobject.ipaddress(0) !=null && objobject.ipaddress(0) != "undefined" && objobject.dnsserversearchorder!=null) 
                 sipaddr = objobject.ipaddress(0); 
                if(objobject.macaddress != null &&objobject.macaddress != "undefined") 
             smacaddr = objobject.macaddress; 
                if(objobject.dnshostname != null &&objobject.dnshostname != "undefined") 
                       sdnsname = objobject.dnshostname; 
       } 
  </script> 

<script for="foo" event="oncompleted(hresult,perrorobject, pasynccontext)" language="jscript"> 
  myform.macaddress.value=smacaddr; 
  myform.ipaddress.value=sipaddr; 
  myform.hostname.value=sdnsname; 
  </script>