0

I have an scenario in my web application that need to find out the MAC address of the client by either java script or server side code.

Please help me to resolve this issue.

Thanks, Tamilselvan S.

3
  • 1
    Did you try anything yet? I have found many resources on this topic, but unfortunately nothing that worked for me. Note that everything I found imply that the client have to authorize your application, so if your goal is to get the MAC address of the client without him knowing it... Well good luck Commented Feb 21, 2018 at 7:42
  • 1
    Possible duplicate of Reliable method to get machine's MAC address in C# or how to get mac address of client that browse web site by asp.net mvc c# (top 2 google results for "get client mac address in c#") Commented Feb 21, 2018 at 8:17
  • Beside that most sources clearly state that it's not easily possible to read the MAC address of a client (at least, remotely), I also need to ask: For what reason? The MAC address is often mistaken for a reliable, unique and secure way to identify the client, which it isn't. Commented Feb 21, 2018 at 9:09

1 Answer 1

0

Client IP address or client MAC address? The first one can be retrieved by using Page.Request.UserHostAddress. The second problem (MAC address) is slightly more complicated and you need to use WMI. You need to create an object in JavaScript, query the WMI and pass the information back to the server. In addition you need to allow access to unsigned ActiveX in IE. Try the below one.

<script type="text/javascript">
        var macAddress = "";
        var ipAddress = "";
        var computerName = "";
        var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}");
        e = new Enumerator(wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"));
        for(; !e.atEnd(); e.moveNext()) {
            var s = e.item(); 
            macAddress = s.MACAddress;
            ipAddress = s.IPAddress(0);
            computerName = s.DNSHostName;
        } 
    </script>

Instead of Win32_Processor, here we'll access Win32_NetworkAdapterConfiguration to read network related details like the MAC Address, IP Address and the computer name.

Then we can simply use textboxes to display that information or whatever you like.

<input type="text" id="txtMACAdress" />
<input type="text" id="txtIPAdress" />
<input type="text" id="txtComputerName" />

<script type="text/javascript">
    document.getElementById("txtMACAdress").value = unescape(macAddress);
    document.getElementById("txtIPAdress").value = unescape(ipAddress);
    document.getElementById("txtComputerName").value = unescape(computerName);
</script>
Sign up to request clarification or add additional context in comments.

6 Comments

@Mohan Srinivas, I have tried to run the above html in IE with Enabling Activex. But I am getting error saying "getObject is undefined" and resultant the textboxes were empty
Mark answer if the answer is helpful.
IE with enabled Active X... this is a highly hypothetical scenario, especially outside the Intranet it's outdated, harmful and dangerous
yes @thmshd that's why mentioned 'The second problem (MAC address) is slightly more complicated '
@MohanSrinivas OP tells you your solution isn't working for him, explains what results he gets (and what he doesn't), and all answer he gets from you is "Mark answer if the answer is helpful"? I'm I the only one puzzled by this? Also note that the "accept answer" button is not here to mark "helpful" answers (there's the upvote button for this), it is here to say "this answer solved my problem or was the most helpful" (and in the last case, the OP should wait a little while before doing so - in case a better solution shows up)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.