1

How to get the MacAddress of End User Machine in asp.net

    Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
    Dim sMacAddress As String = String.Empty
    Dim adapter As NetworkInterface
    For Each adapter In nics
        If sMacAddress = String.Empty Then
            Dim properties As IPInterfaceProperties = adapter.GetIPProperties()
            sMacAddress = adapter.GetPhysicalAddress().ToString()
        End If
    Next

By using the above code i am getting Application Host server Machine's macaddress

Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
Raveendra
  • 19
  • 1
  • 1
    dup ? http://stackoverflow.com/questions/19285957/how-to-get-public-ip-address-of-a-user-in-c-sharp – Arsen Mkrtchyan Feb 12 '14 at 14:00
  • Please explain the actual problem you're trying to solve. You most likely don't need the client's MAC address for that. – CodeCaster Feb 12 '14 at 14:06
  • @CodeCaster Most likely, it's some kind of problem like authentication or preventing multiple votes from one computer etc. - it would be nice if you could use a MAC, but you can't :D – Luaan Feb 12 '14 at 14:11

1 Answers1

2

Simple answer - you can't. The MAC address you're going to get (if any) will be the last network element before your server, not the one of the browser's NIC. In other words, it could work on your local network (or intranet), but it will not work in a realistic, internet situation.

And yes, your code is getting the MAC address of the NICs on the server, that shouldn't be suprising at all :) You'd have to have the code running on the client to give you the client's MAC address - the code runs on the server, and as such, gives the server's MAC address.

Luaan
  • 62,244
  • 7
  • 97
  • 116