Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the MAC-Address of a client with a browser

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

like image 401
chris6523 Avatar asked Apr 23 '12 08:04

chris6523


People also ask

Can I get MAC address from browser?

The only way to get the visitor's MAC address is to run code on his laptop, from the browser. There is no way to do it since it would be a breach of privacy or security. There are several workarounds like running Active-X controls for Internet Explorer only or running XPCOM for Mozilla Firefox only.

How do I find the client MAC address of a website?

To get the MAC address, pass the parameter 'getmac' which returns the MAC address of the client. 'getmac' is a CMD command to get the MAC address.

Can I get MAC address from http request?

MAC is a property of a TCP packet, and on HTTP level there're no packets or MACs (for example, a single HTTP request might be assembled of several TCP packets). You could try using a packet sniffer (like WireShark) to capture TCP packets, and then analyze them to extract MACs and map them to HTTP requests.


1 Answers

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).

like image 162
kuba Avatar answered Oct 04 '22 00:10

kuba