我有以下问题: 我有一个网络服务器。这个网络服务器在路由器后面。问题是,我需要一个客户端的MAC地址,在服务器上打开一个网站用于进一步的目的。我已经尝试通过ActiveX-Object获取MAC地址,但客户端需要安装WMI。这是实际的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script id="clientEventHandlersJS" language="javascript">
function Button1_onclick() {
var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var service = locator.ConnectServer(".");
var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
var e = new Enumerator (properties);
document.write("<table border=1>");
dispHeading();
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
document.write("<tr>");
document.write("<td>" + p.Caption + "</td>");
document.write("<td>" + p.IPFilterSecurityEnabled + "</td>");
document.write("<td>" + p.IPPortSecurityEnabled + "</td>");
document.write("<td>" + p.IPXAddress + "</td>");
document.write("<td>" + p.IPXEnabled + "</td>");
document.write("<td>" + p.IPXNetworkNumber + "</td>");
document.write("<td>" + p.MACAddress + "</td>");
document.write("<td>" + p.WINSPrimaryServer + "</td>");
document.write("<td>" + p.WINSSecondaryServer + "</td>");
document.write("</tr>");
}
document.write("</table>");
}
function dispHeading()
{
document.write("<thead>");
document.write("<td>Caption</td>");
document.write("<td>IPFilterSecurityEnabled</td>");
document.write("<td>IPPortSecurityEnabled</td>");
document.write("<td>IPXAddress</td>");
document.write("<td>IPXEnabled</td>");
document.write("<td>IPXNetworkNumber</td>");
document.write("<td>MACAddress</td>");
document.write("<td>WINSPrimaryServer</td>");
document.write("<td>WINSSecondaryServer</td>");
document.write("</thead>");
}
</script>
</head>
<body>
<INPUT id="Button1" type="button" value="Button" name="Button1" language="javascript" onclick="return Button1_onclick()">
</body>
当您单击该按钮时,它应该返回一个包含网络配置的表,但这对我不起作用。我想知道,如果有另一种解决方案可以通过浏览器获取客户端的MAC地址。我也不想限制Internet Explorer的使用。在此先感谢您的帮助。
此致 克里斯
答案 0 :(得分:5)
您似乎可以使用Java Applet执行此操作,请参阅https://forums.oracle.com/forums/thread.jspa?threadID=1144276和http://techdetails.agwego.com/2008/02/11/37/上的postst。
不确定您是否需要用户同意此安全警告,我还没有尝试过。
可能没有更好的方法,因为ActiveX只能在Windows(和IE)上运行,并且没有这样的API可以在任何标准HTML或JavaScript中获取MAC地址。我不知道Flash是否对此有用,但我对此表示怀疑。
但是,您获取用户MAC地址的原因似乎有效,但我仍然认为推断出任何信息并不是一个好主意,因为它可能会被欺骗/更改,并且在某些情况下可能无法正常显示。如果你能为你的问题找到更好的解决方案(不涉及获取MAC地址),你会做得更好。
答案 1 :(得分:0)
在我之前的项目中。我们在浏览器javascript中使用websocket与在同一台机器上运行的本机代码C#dll进行通信。本机代码可以检索任何系统信息,MAC地址和其他系统信息,如内存,磁盘空间等.Node.js也可以用来替换C#,以便打破windows machin和MAC机器的限制。使用安装盾将整个应用程序(chrome浏览器+本机代码)下载到客户端。