To fetch or get the MAC Address in C# application we have to use “Win32_NetworkAdapterConfiguration” WMI class. This class represent the attributes and behavior of the network adapter card. This class includes extra properties and methods that support the management of the TCP/IP and Internetwork Packet Exchange (IPX) protocols that are independent from the network adapter. These are the list of the Properties of the “Win32_NetworkAdapterConfiguration” class.
boolean ArpAlwaysSourceRoute;
boolean ArpUseEtherSNAP;
string Caption;
string DatabasePath;
boolean DeadGWDetectEnabled;
string DefaultIPGateway[];
uint8 DefaultTOS;
uint8 DefaultTTL;
string Description;
boolean DHCPEnabled;
datetime DHCPLeaseExpires;
datetime DHCPLeaseObtained;
string DHCPServer;
string DNSDomain;
string DNSDomainSuffixSearchOrder[];
boolean DNSEnabledForWINSResolution;
string DNSHostName;
string DNSServerSearchOrder[];
boolean DomainDNSRegistrationEnabled;
uint32 ForwardBufferMemory;
boolean FullDNSRegistrationEnabled;
uint16 GatewayCostMetric[];
uint8 IGMPLevel;
uint32 Index;
uint32 InterfaceIndex;
string IPAddress[];
uint32 IPConnectionMetric;
boolean IPEnabled;
boolean IPFilterSecurityEnabled;
boolean IPPortSecurityEnabled;
string IPSecPermitIPProtocols[];
string IPSecPermitTCPPorts[];
string IPSecPermitUDPPorts[];
string IPSubnet[];
boolean IPUseZeroBroadcast;
string IPXAddress;
boolean IPXEnabled;
uint32 IPXFrameType[];
uint32 IPXMediaType;
string IPXNetworkNumber[];
string IPXVirtualNetNumber;
uint32 KeepAliveInterval;
uint32 KeepAliveTime;
string MACAddress;
uint32 MTU;
uint32 NumForwardPackets;
boolean PMTUBHDetectEnabled;
boolean PMTUDiscoveryEnabled;
string ServiceName;
string SettingID;
uint32 TcpipNetbiosOptions;
uint32 TcpMaxConnectRetransmissions;
uint32 TcpMaxDataRetransmissions;
uint32 TcpNumConnections;
boolean TcpUseRFC1122UrgentPointer;
uint16 TcpWindowSize;
boolean WINSEnableLMHostsLookup;
string WINSHostLookupFile;
string WINSPrimaryServer;
string WINSScopeID;
string WINSSecondaryServer;
Note:- The “Win32_NetworkAdapterConfiguration” class is present under the System.Management Namespace. So before using the “Win32_NetworkAdapterConfiguration” class you must add the refrence of System.Management namespace in your project.
Here is the a function written in c#, that return the MAC address of the system
private string GetMacAddress()
{
string macid = string.Empty;
ManagementClass mac = new ManagementClass(“Win32_NetworkAdapterConfiguration”);
ManagementObjectCollection macObjCol = mac.GetInstances();
foreach (ManagementObject mo in macObjCol)
{
if (macid.Equals(string.Empty))
{
if ((bool)mo["IPEnabled"] == true)
{
macid = mo["MacAddress"].ToString();
mo.Dispose();
}
}
}
return macid;
}
Used Namespace
System.Management;




