Extracting MAC address using C#

CsharpProgrammingServer Side Programming

A MAC address of a device is a media access control address. It is a unique identifier assigned to a network.

The MAC address technology is used by many technologies such as Ethernet, Bluetooth, Fibre Channel, etc.

Here, we will use the following method to check for all the network interfaces on the computer.


For this, the NetworkInterfaceType Enumeration is also used to specify the type of network interfaces.

string addr = "";
foreach (NetworkInterface n in NetworkInterface.GetAllNetworkInterfaces()) {
   if (n.OperationalStatus == OperationalStatus.Up) {
      addr += n.GetPhysicalAddress().ToString();
return addr;

Above, we have used the GetPhysicalAddress() method to extract the MAC address.

Updated on 23-Jun-2020 15:06:50