JS获取客户端MAC地址

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title>JS获取客户端MAC地址</title>
5 <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
6 <meta name="generator" content="editplus" />
7 <meta name="author" content="" />
8 <meta name="keywords" content="" />
9 <meta name="description" content="" />
10 <style type="text/css">
11
12 </style>
13 <script event="OnObjectReady(objObject,objAsyncContext)" for="foo">
14 if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true) {
15 if(objObject.MACAddress != null && objObject.MACAddress != "undefined" && objObject.DNSServerSearchOrder!=null)
16 MACAddr = objObject.MACAddress;
17 if(objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined" && objObject.DNSServerSearchOrder!=null)
18 IPAddr = objObject.IPAddress(0);
19 if(objObject.DNSHostName != null && objObject.DNSHostName != "undefined")
20 sDNSName = objObject.DNSHostName;
21 }
22 </script>
23 <script type="text/javascript">
24 var MACAddr ;
25 var IPAddr ;
26 var DomainAddr;
27 var sDNSName;
28 function init() {
29 var service = locator.ConnectServer();
30 service.Security_.ImpersonationLevel=3;
31 service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
32 }
33
34 function getMac() {
35 document.getElementById('txtMac').value = unescape(MACAddr);
36 }
37 </script>
38 </head>
39
40 <body onload="init()">
41 <object id="locator" classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" VIEWASTEXT></object>
42 <object id="foo" classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>
43
44 <input type="text" id="txtMac" />
45 <input type="button" id="btn" value="获取Mac地址" onclick="getMac();" />
46 </body>
47 </html>

 

posted @ 2012-01-12 10:21  gsbhz  阅读(5673)  评论(4编辑  收藏  举报