@Blog.Author(Nandip Makwana) .LearningExperience(ASP.NET, ASP.NET MVC, IIS, jQuery & Technology Surrounding it...)

April 3, 2010 comment

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()

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.
comments powered by Disqus

Featured Content

Resources & Tools

About Nandip Makwana

Nandip Makwana is passionate about digital world and web. He completed his Masters in Computer Application in June 2011. Currently he is working as a Software Engineer. He has shown great promise and command over ASP.NET and technologies surrounding it during his academic years and professorial life...continue reading