JScript中調用ActiveX擷取訪客網卡MAC地址實現代碼_應用技巧

來源:互聯網
上載者:User

JScript調用activeXObject擷取訪客的網卡MAC地址,注意只能IE下運行(IE8+沒測試),會有安全提示,提示如下:

複製代碼 代碼如下:

在此頁上的ActiveX控制項和本頁上的其他部分的互動可能不安全。你想允許這種互動嗎?

注意選擇”是“,要不報錯無法擷取:

原始碼如下:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.