Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Does anybody know reliable way to get MAC address of Client PC using ASP.Net / C#

    • 0
    • 1
    • 0
    • 2
    • 0
    • 0
    • 0
    • 5.16k
    Answer it

    Does anybody know reliable way to get MAC address of Client PC using ASP.Net / C#. I am using framework 3.5.

    Below is the code I am using working fine on locally / IIS. But this works on a site having full trust level. But doesn't work with medium trust level.

    <system.web>
            <trust level="Medium">
        </trust></system.web></p>
    
    <p>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 <br>
            {
                IPInterfaceProperties properties = adapter.GetIPProperties();
                sMacAddress = adapter.GetPhysicalAddress().ToString();
            }
        } return sMacAddress;
    }
    

    Can somebody provide me an alternate way to get Mac address of the client

 2 Answer(s)

  • private static string getMacAddress(string distIP)
        {
    
            IPAddress dIP = IPAddress.Parse(distIP); // the destination IP address
    
            byte[] macAddr = new byte[6];
            uint macAddrLen = (uint)macAddr.Length;
    
            if (SendARP(BitConverter.ToInt32(dIP.GetAddressBytes(), 0), 0, macAddr, ref macAddrLen) != 0)
                throw new InvalidOperationException("SendARP failed.");
    
            string[] str = new string[(int)macAddrLen];
            for (int i = 0; i < macAddrLen; i++)
                str[i] = macAddr[i].ToString("x2");
    
            return string.Join("-", str);
        }
    
  • The code mentioned here will only work for the machine where it runs being the server side code.

    We have tried to search for the MAC IP address in the request we get from the client but we did not get any success. We have also tried fetching it using javascript but it only works on IE browser which wont serve the purpose for MAC user.

    Its still open from our side and will share the solution if we find any.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: