troubleshooting Question

How to get Ethernet MAC address? NOT enabled MAC Address

Avatar of snowycanada
snowycanadaFlag for Afghanistan asked on
.NET ProgrammingC#
3 Comments2 Solutions2346 ViewsLast Modified:
As the title, I just need Ethernet network adapter's physical address to create password. Viusal studio 2010 C#, Windows 7 professional
Had tried different way but failed.
Seems each solution just catch the enabled one.
As attached sample1, I had tried sort by spercial word, but not every ethernet adapter description has "PCI"
Attached sample2 is the way to get the enable adapter MAC address, unuseful either.

How can i get the ethernet adapter physical address when the computer is working in wireless network?
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            string MACAddress = String.Empty;
            foreach (ManagementObject mo in moc)
                if (MACAddress == String.Empty) // only return MAC Address from first card
                    if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();

            MACAddress = MACAddress.Replace(":", "");
NetworkInterface[] fNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
             foreach (NetworkInterface adapter in fNetworkInterfaces)
                 string strDescription = adapter.Description.ToString();
                 //the MAC address which has "PCI" and not has "Wireless" is ethernet MAC
                 if (strDescription.Contains("PCI") && !strDescription.Contains("Wireless"))
                     strMAC = adapter.GetPhysicalAddress().ToString();
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros