标签:
最近遇到一个需求,医院要求呼叫中心账号必须对应MAC地址,也就是说该MAC地址必须和呼叫中心账号对应才可使用,这可就难道我了,这需求就要求每次都判断用户登录的电脑MAC地址是否有呼叫中心账号,当然只针对IE浏览器,毕竟其他浏览器是直接就给禁止此功能的。
那么首先问题一:如何才能通过页面访问得到本地MAC地址
问题二:每台电脑上都有多个MAC地址,那么应该选用哪一个MAC地址
MAC地址是每台电脑链接网络的物理地址,是唯一标识,想要从浏览器获取电脑的信息,那么就需要ActiveX,所以其他浏览器是没有办法通过js获取MAC地址的。
方法一:(推荐)需要客户端设置将服务器地址加入受信任站点
<html>
<head>
<title>获取客户端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")
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>
方法二:
<!DOCTYPE html>
<html>
<head>
<title>获取电脑硬件信息</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=GBK">
</head>
<body>
<script id="clientEventHandlersJS" language="javascript" charset="utf-8">
http://www.w3school.com.cn/htmldom/dom_obj_navigator.asp
/******************************************以上为浏览器信息,以下为pc信息************************************************/ try { var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
//获取网络连接信息
function ipinfo(){
var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE");
var e = new Enumerator (properties);
var info="<table border=1>";
info+="<tr bgcolor=‘#CDEDED‘ style=‘font-weight: bold;‘ >
<td width=‘450‘>网络连接信息:</td></tr>";
var i=1;
for (;!e.atEnd();e.moveNext ()){
var p = e.item ();
info+="<tr style=‘color: red‘><td >MAC地址"+i+":" + p.MACAddress + "</td></tr>"; info+="<tr style=‘color: red‘><td >IP地址"+i+":" + p.IPAddress(0) + "</td></tr>"; i++; }
info+="</table>"; return info; }
function pcInfo() {//所有信息
var info=ipinfo();
/* info+=disk(); info+=raminfo();
info+=mainBoard();
info+=ipinfo();
info+=keyBoardInfo();
info+=RomInfo();
info+=softDisk(); */ document.getElementById(‘elInfo‘).innerHTML=info;
return info; } } catch (e) { document.write(e); }
/******************************************以上为pc信息************************************************/
</script>
</head>
<body > <!-- <INPUT id="Button1" type="button" value="浏览器所有信息" name="Button1" language=javascript onclick="allinfo()"> -->
<INPUT id="Button1" type="button" value="客户端pc信息" name="Button1" language=javascript onclick="pcInfo()">
<div id="elInfo" >
</div> </body> </html>
标签:
原文地址:http://www.cnblogs.com/zzj0410/p/4846631.html