How to get MAC Address through C# .NET
Many time in our application we may require that we need to fetch MAC Address of network adapter card and other detail about network adapter. fallowing are the sample application with explanation in C# .NET on How to get MAC Address and other detail about network adapter.
Following are the step to achieve it.
Create new console application
Add reference to System.Management Assembly
Copy following code in void main()
Run the application
That's it you will get info about Adapter.
Explanation About Code
What i have used in supplied code is that i have used "Win32_NetworkAdapter" class which is called windows management class (and this class is supplied with windows itself) which give info about NIC Card on System.
Following are the step to achieve it.
Create new console application
Add reference to System.Management Assembly
Copy following code in void main()
System.Management.ManagementClass objMgmtCls = new
System.Management.ManagementClass("Win32_NetworkAdapter");
foreach (System.Management.ManagementObject objMgmt in objMgmtCls.GetInstances())
{
Console.WriteLine("Manufacturer : " + objMgmt["Manufacturer"]);
Console.WriteLine("Adapter Name : " + objMgmt["Caption"]);
Console.WriteLine("MAC Address : " + objMgmt["MACAddress"]);
}
Run the application
That's it you will get info about Adapter.
Explanation About Code
What i have used in supplied code is that i have used "Win32_NetworkAdapter" class which is called windows management class (and this class is supplied with windows itself) which give info about NIC Card on System.