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.

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.

raja
Published on 19-Sep-2018 10:46:05
Advertisements