Avatar of StevenH
StevenH
Flag for Canada asked on

How to get Ethernet MAC address? NOT enabled MAC Address

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();
                }
                mo.Dispose();
            }

            MACAddress = MACAddress.Replace(":", "");

Open in new window

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

Open in new window

.NET ProgrammingC#

Avatar of undefined
Last Comment
StevenH

8/22/2022 - Mon
SOLUTION
ukerandi

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
dj_alik

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
StevenH

ASKER
di_alik, you are experts
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck