游览器获取Mac地址(仅限于IE游览器,需要用到ActiveX控件),非IE游览器做了提醒
1 <html> 2 <head> 3 <title>JScript+ActiveX获取访客MAC网卡地址</title> 4 </head> 5 <body> 6 <object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" style="display:none;visibility:hidden"></object> 7 <object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo" style="display:none;visibility:hidden"></object> 8 <form name="myForm"> 9 <br/>MAC地址:<input type="text" name="macAddress"> 10 <br/>IP地址:<input type="text" name="ipAddress"> 11 <br/>主机名:<input type="text" name="hostName"> 12 </form> 13 </body> 14 </html> 15 <script language="javascript"> 16 var userAgent = navigator.userAgent; 17 var isOpera = userAgent.indexOf("Opera") > -1; 18 if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) { 19 20 } 21 else 22 { 23 alert("请使用IE游览器访问!您的请求被拒绝。"); 24 } 25 26 var sMacAddr = ""; 27 var sIPAddr = ""; 28 var sDNSName = ""; 29 var service = locator.ConnectServer(); 30 service.Security_.ImpersonationLevel = 3; 31 service.InstancesOfAsync(foo, \'Win32_NetworkAdapterConfiguration\'); 32 33 </script> 34 <script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript"> 35 if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true){ 36 if(objObject.IPEnabled && objObject.IPAddress(0) !=null && objObject.IPAddress(0) != "undefined" && objObject.DNSServerSearchOrder!=null) 37 sIPAddr = objObject.IPAddress(0); 38 if(objObject.MACAddress != null &&objObject.MACAddress != "undefined") 39 sMacAddr = objObject.MACAddress; 40 if(objObject.DNSHostName != null &&objObject.DNSHostName != "undefined") 41 sDNSName = objObject.DNSHostName; 42 } 43 </script> 44 45 <script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript"> 46 myForm.macAddress.value=sMacAddr; 47 myForm.ipAddress.value=sIPAddr; 48 myForm.hostName.value=sDNSName; 49 </script>
不推荐啊不推荐~
这样获取,是没有办法的办法!