120

I know that we can get the MAC address of a user via IE (ActiveX objects).

Is there a way to obtain a user's MAC address using JavaScript?

p.campbell
  • 95,348
  • 63
  • 249
  • 319
Adhip Gupta
  • 6,873
  • 7
  • 32
  • 46

7 Answers7

71

I concur with all the previous answers that it would be a privacy/security vulnerability if you would be able to do this directly from Javascript. There are two things I can think of:

  • Using Java (with a signed applet)
  • Using signed Javascript, which in FF (and Mozilla in general) gets higher privileges than normal JS (but it is fairly complicated to set up)
Grey Panther
  • 12,508
  • 6
  • 43
  • 64
  • 5
    I was courious to know, can we get a unique information like mac adress or serial number or something like that from user via JavaScript? Or PC name? – Flamur Beqiraj Mar 01 '19 at 12:49
64

The quick and simple answer is No.

Javascript is quite a high level language and does not have access to this sort of information.

GateKiller
  • 71,469
  • 71
  • 169
  • 203
  • 1
    then what about all the google search result providing sample codes to get MAC Address – Moon Dec 26 '10 at 02:53
  • 15
    I've had a quick look around Google and all of the pages I read were IE only solution which relied on using ActiveX objects. If you could post a link showing otherwise... – GateKiller Jan 12 '11 at 16:52
  • 32
    I really don't think being a "high level language" has anything to do with MAC addresses, since any server-side programming language allows you do get access the ARP table, even indirectly (e.g. through a subprocess). I think "client-side language" would work better... – kirbyfan64sos Oct 06 '16 at 19:51
  • 8
    There is no reason why an high level language wouldn't have access to low level hardware information. In this case this doesn't happen because it would be a security problem. – nsn May 07 '17 at 09:37
39

No you cannot get the MAC address in JavaScript, mainly because the MAC address uniquely identifies the running computer so it would be a security vulnerability.

Now if all you need is a unique identifier, I suggest you create one yourself using some cryptographic algorithm and store it in a cookie.

If you really need to know the MAC address of the computer AND you are developing for internal applications, then I suggest you use an external component to do that: ActiveX for IE, XPCOM for Firefox (installed as an extension).

Vincent Robert
  • 34,658
  • 14
  • 79
  • 118
7

If this is for an intranet application and all of the clients use DHCP, you can query the DHCP server for the MAC address for a given IP address.

Ryan Ahearn
  • 7,776
  • 6
  • 48
  • 56
7

Nope. The reason ActiveX can do it is because ActiveX is a little application that runs on the client's machine.

I would imagine access to such information via JavaScript would be a security vulnerability.

Seibar
  • 66,138
  • 37
  • 86
  • 99
5

i was looking for the same problem and stumbled upon the following code.

How to get Client MAC address(Web):

To get the client MAC address only way we can rely on JavaScript and Active X control of Microsoft.It is only work in IE if Active X enable for IE. As the ActiveXObject is not available with the Firefox, its not working with the firefox and is working fine in IE.

This script is for IE only:

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;
}

showMacAddress();
<div id='box'></div>
ntfs.hard
  • 333
  • 1
  • 3
  • 15
Ad Kahn
  • 501
  • 4
  • 6
-2

No you can't obtain a user's MAC address using JavaScript in another way, just by using active X op for Microsoft in IE browser