Extracting MAC address using C#


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.

NetworkInterface.GetAllNetworkInterfaces

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();
      break;
   }
}
return addr;

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

Updated on: 23-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements