First you need to add refererense from for get the mac address of network adapter.
Add Reference --> .NET --> System.Management.
----------------------------*****************--------------------------
To get mac address of Local system.
using System.Managemant;
public static string GetMacAddress()
{
string Mac = string.Empty;
ManagementClass MC = new ManagementClass("Win32_NetworkAdapter");
ManagementObjectCollection MOCol = MC.GetInstances();
foreach (ManagementObject MO in MOCol)
if (MO != null)
{
if (MO["MacAddress"] != null)
{
Mac = MO["MACAddress"].ToString();
if (Mac != string.Empty)
break;
}
}
return Mac;
}
-------------------------------------------------------------------------------
To get mac address of when your system in on LAN on etharnet .
Using System.Management;
public PhysicalAddress GetMacAddress() //Get MAC Address of the machine.
{
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
// Only consider Ethernet network interfaces
if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
nic.OperationalStatus == OperationalStatus.Up)
{
return nic.GetPhysicalAddress();
}
}
return null;
}