MAC addresses in JavaScript

JavascriptMac Address

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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)

Solution 2 - Javascript

The quick and simple answer is No.

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

Solution 3 - Javascript

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

Solution 4 - Javascript

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.

Solution 5 - Javascript

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.

Solution 6 - Javascript

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>

Solution 7 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAdhip GuptaView Question on Stackoverflow
Solution 1 - JavascriptGrey PantherView Answer on Stackoverflow
Solution 2 - JavascriptGateKillerView Answer on Stackoverflow
Solution 3 - JavascriptVincent RobertView Answer on Stackoverflow
Solution 4 - JavascriptRyan AhearnView Answer on Stackoverflow
Solution 5 - JavascriptSeibarView Answer on Stackoverflow
Solution 6 - JavascriptAd KahnView Answer on Stackoverflow
Solution 7 - Javascriptبدور فهدView Answer on Stackoverflow