<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>获取mac地址</title> </head> <body> <SCRIPT language="JavaScript"> function MacInfo(){ //访问到WbemScripting对象 var locator =new ActiveXObject ("WbemScripting.SWbemLocator"); //访问本地电脑 var service = locator.ConnectServer("."); //获取我们需要的对象的记录集 var properties = service.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =True"); var e =new Enumerator (properties); { var p = e.item(); var mac = p.MACAddress; alert('MAC地址:'+mac) } } </SCRIPT> <button onclick="MacInfo()">点击我查看MAC</button> </body> </html>
仅支持IE,需要谷歌支持自己编写扩展