0

I'm trying to getting a client mac address. I used that code but it getting the server mac address. How I can solve this issue?

        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;
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Which client, how did the client connect to the server? Is your C# program handling incoming connections? The code you have above is only for the physical adapters on the computer running the code. – Nate Feb 26 '14 at 16:11
  • any client I coded on a web page. i try to get client mac adress. because that client join to poll. They join that poll 1 time. I chech on that computer mac adress. – Korhan Koray Kizilin Feb 26 '14 at 16:18
  • Probably cannot be done, see also: http://stackoverflow.com/questions/3309122/how-can-i-get-a-mac-address-from-an-http-request – Nate Feb 26 '14 at 18:51
  • I read that subject. I understand that is impossible... – Korhan Koray Kizilin Feb 26 '14 at 22:25

1 Answers1

0

Server side code is not going to read the clients MAC address, however you should be able to read the client MAC from within the server OS. IPGlobalProperties can be used to show active connections.

Also issuing an "arp -a" command on the local server will show the IP Address and MAC address of clients connected to the server. So since the client is connecting to the server arp -a will show the IP address and MAC assuming you know how to issue a command to the command prompt via c#.

  • have you got any examples about this subject ? – Korhan Koray Kizilin Feb 27 '14 at 11:40
  • As is stated in the answer that I linked above, this will only work if the clients are on the same network segment. Which is highly unlikely. It is a remote possibility, but I'm thinking for a regular web server, not very. – Nate Feb 27 '14 at 16:32