Here’s a way to get the local machine’s MAC address in C#. Note that there may be various MAC addresses (Ethernet cards, local loopback devices, hooked up 3G devices etc.), so we try to find only the Ethernet MAC address.

static string GetMacAddress()
{
  string macAddresses = "";
  foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
  {
    // Only consider Ethernet network interfaces, thereby ignoring any
    // loopback devices etc.
    if (nic.NetworkInterfaceType != NetworkInterfaceType.Ethernet) continue;
    if (nic.OperationalStatus == OperationalStatus.Up)
    {
      macAddresses += nic.GetPhysicalAddress().ToString();
      break;
    }
  }
  return macAddresses;
}

13 comments

Archived from the site's previous comment system. New comments are closed.

Naresh

thanks. this was useful to me.

prasad

Thanks very much. That works finally

Zafer

Thanks.

khan

thanks..very useful...

miki

Be carefull, you should also check for wireless network, not only ethernet >> Wireless80211 <<

yishagerew

bravo!

jay

Nice Thnx.....

Rowshan

Very helpful....

nani

nice one ,but localhost displays system mac address problem is when hosting in server system the mac address displays server mac address.i want to display local mac address when run the application from server

Niyal

hello,
thanks for the code, but i need it in another way, i want to register pc's mac address when i run installation of my application, can anyone help me out??

Pavel

Very useful !

monal

Hii,

kindly help i want the MAC Address of all the users whom using my website. i tried your code but it shows the MAC Address of where it have been deployed. i want the MAC Addresses of the user whom currently using on(mobile,tab,computer,laptop,etc any machine).

please help...

Sharath Raj

Hi,
i want to make my application run only on local ethernet mac address ..how do we do it??