Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
How to get client system (browser) MAC Address.

After I launch in my project in one domain like www.xyx.com, it returns server MAC Address, instead of Client system MAC Address.
If anybody knows, please help me.
I try the following solutions, but it returns only server MAC Address

Solution 1:

C#
private string GetMAC()
{
   string macAddresses = "";

   foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
   {
      if (nic.OperationalStatus == OperationalStatus.Up)
      {
         macAddresses += nic.GetPhysicalAddress().ToString();
         break;
      }
   }
   return macAddresses;
}

Solution 2:

C#
public string GetMACAddress()
{
   ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
   ManagementObjectCollection moc = mc.GetInstances();
   string MACAddress = String.Empty;
   foreach (ManagementObject mo in moc)
   {
      if (MACAddress == String.Empty) // only return MAC Address from first card   
      {
         if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
      }
      mo.Dispose();
   }

   MACAddress = MACAddress.Replace(":", "");
   return MACAddress;
}
Posted
Updated 21-Oct-13 7:29am
v3
Comments
Ranjan.D 21-Oct-13 12:08pm    
Obviously your code doesn't work as expected because the compiled code runs at server (hosted in xyz domain) and it will return the mac address of the server
Ranjan.D 21-Oct-13 12:11pm    
Did you intend to get client's MAC address or IP Address ?

You can't get the Client MAC address on the server - it isn't transferred beyond the router, and it's only used there to initially identify the equipment so that an internal LAN / WAN IP address can be assigned.

Whenever you query NIC data on the server, you will get server related data, not client.
 
Share this answer
 
Your code snippets are for retrieving data from interfaces where your code is running. It is straightforward that you get server's MAC addresses.
As OriginalGriff stated you can't really get client MAC, only if it is in your local VLAN, which is quite uncommon. But why do you need that? For identifying a client? It's not suitable for that. You could use some client side components to get it - but it would be highly inefficient, and even if you could get it, it can be changed, thus it is unreliable.
There are better means for that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900