0

How to get MAC Address of user accessing the website. The website is using MVC and hosted on IIS.

public string GetMACAddress()
{
    NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
    String sMacAddress = string.Empty;
    foreach (NetworkInterface adapter in nics)
    {
        if (sMacAddress == String.Empty)// only return MAC Address from first card
        {
            IPInterfaceProperties properties = adapter.GetIPProperties();
            sMacAddress = adapter.GetPhysicalAddress().ToString();
        }
    } return sMacAddress;
}

I am using the above code but this doesn't seems to work.

Rohit Kumar
  • 776
  • 3
  • 21
  • What does it mean `it doesn't seem to work`? Also your code doesn't check the IP of the client machine. First you need to get the IP of the client machine. https://stackoverflow.com/questions/2577496/how-can-i-get-the-clients-ip-address-in-asp-net-mvc – Chetan Oct 10 '17 at 04:47
  • It's giving null values – Rohit Kumar Oct 10 '17 at 04:49
  • https://www.codeproject.com/Questions/709517/How-to-get-clients-MAC-Address-in-Asp-Net – Chetan Oct 10 '17 at 04:52
  • It suggest MAC Address is not unique, Unless your clients are on the same physical subnet as the server you can't get the MAC addresses. Means MAC address for all the user accessing my websote wouldn't be possible? – Rohit Kumar Oct 10 '17 at 04:55
  • Technically you never know the IP of the actual user machine because it is not directly connected to your server. There will always be a network facing device via which it connects to internet and then to your server. So your server knows is the IP of that device. – Chetan Oct 10 '17 at 05:02
  • Is there any way I can get physical address of user access my site. – Rohit Kumar Oct 10 '17 at 05:11
  • Request.ServerVariables["REMOTE_HOST"] for IP adress Request.UserHostAdress for mac adress – erdi yılmaz Oct 10 '17 at 05:52

0 Answers0