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.

Vidhselva
  • 117
  • 2
  • 15
  • 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 – Rafalon Feb 21 '18 at 07:42
  • 1
    Possible duplicate of [Reliable method to get machine's MAC address in C#](https://stackoverflow.com/questions/850650/reliable-method-to-get-machines-mac-address-in-c-sharp) or [how to get mac address of client that browse web site by asp.net mvc c#](https://stackoverflow.com/questions/8756179/how-to-get-mac-address-of-client-that-browse-web-site-by-asp-net-mvc-c-sharp) (top 2 google results for "get client mac address in c#") – Rafalon Feb 21 '18 at 08: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](https://superuser.com/a/968346/92067). – thmshd Feb 21 '18 at 09:09

1 Answers1

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>
Mohan Srinivas
  • 302
  • 3
  • 13
  • @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 – Vidhselva Feb 21 '18 at 09:19
  • Mark answer if the answer is helpful. – Mohan Srinivas Feb 21 '18 at 09:23
  • 1
    IE with enabled Active X... this is a highly hypothetical scenario, especially outside the Intranet it's outdated, harmful and dangerous – thmshd Feb 21 '18 at 09:34
  • yes @thmshd that's why mentioned 'The second problem (MAC address) is slightly more complicated ' – Mohan Srinivas Feb 21 '18 at 09:36
  • 1
    @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) – Rafalon Feb 21 '18 at 10:13
  • @ Rafalon he edited the comment man.Before he posted different one.That y i post a comment mark answer ,okay! – Mohan Srinivas Feb 21 '18 at 10:18