Getting the MAC-Address of a client with a browser

自古美人都是妖i 提交于 2019-11-27 18:16:38

问题


I have the following problem: I have a webserver. This webserver is behind a router. The problem is, I need the MAC-Address of a client that opens a website on the server for further purposes. I tried already to get the MAC-Address via an ActiveX-Object, but the client needs WMI installed. Here is the actual code:

<!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>

When you click on the button, it should return a table with the network configuration, but that doesn't work for me. I'd like to know, if there is another solution for getting the MAC-Address of a client via browser. I also don't want to limit the usage on Internet Explorer. Thanks in advance for your help.

Regards, Chris


回答1:


It seems that you can do this using a Java Applet, see postst at https://forums.oracle.com/forums/thread.jspa?threadID=1144276 and http://techdetails.agwego.com/2008/02/11/37/.

Not sure if you need the user to agree a security warning for this or not, I have not tried it.

There is probably no better way, since ActiveX will only work on Windows (and IE only), and there is no such API to get MAC address in any standard HTML or JavaScript. I don't know if Flash can be useful for this, but I doubt that.

However, your reason to get user's MAC address may seem valid, but I still think it's not a good idea to deduce any information it, because it can be spoofed/changed and may not show properly in certain situations. You would do better, if you could come up with a better solution for your problem (not involving grabbing MAC addresses).




回答2:


In my previous project. we used websocket in browser javascript to communicate with a native code, a C# dll, running on the same machine. The native code can retrieve any system info, MAC address and other system info like memeory, disk space, etc. Node.js can be used to replace C# as well just to break the limit of windows machin and into MAC machine. The entire app ( chrome browser + native code ) was downloaded to client using install shield.



来源:https://stackoverflow.com/questions/10277440/getting-the-mac-address-of-a-client-with-a-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!