asp.net网站需要获取客户端的MAC地址。用js什么的都行,但是得保证ie和FF都能用,其他浏览器尽量兼容。能实现吗?有用过的吗?
2 回答
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
需要通过ActiveX获取。
IE下的代码如下(代码来源):
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Getting MAC Address From Javascript(IE Only)</title> <script language="javascript"> function showMacAddress(){ var obj =new ActiveXObject("WbemScripting.SWbemLocator"); var s = obj.ConnectServer("."); var properties = s.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration"); var e =new Enumerator (properties); var output; output='<table border="0" cellPadding="5px" cellSpacing="1px" bgColor="#CCCCCC">'; output=output +'<tr bgColor="#EAEAEA"><td>Caption</td><td>MACAddress</td></tr>'; while(!e.atEnd()) { e.moveNext(); var p = e.item (); if(!p) continue; output=output +'<tr bgColor="#FFFFFF">'; output=output +'<td>'+ p.Caption; +'</td>'; output=output +'<td>'+ p.MACAddress +'</td>'; output=output +'</tr>'; } output=output +'</table>'; document.getElementById("box").innerHTML=output; } </script> </head> <body> <input type="button" value="Show MAC Address" onclick="showMacAddress()"/> <div id="box"> </div> </body> </html>
FireFox中需要安装插件MediaWrap,让FireFox支持ActiveX。(参考自How to get MAC Address in Firefox using Javascript? )
- 2 回答
- 0 关注
- 582 浏览
添加回答
举报
0/150
提交
取消