1

I'm coding a part where the software need to obtain MAC Address of the current PC and found this solution which works for offline too: https://stackoverflow.com/a/15784105/9641721

I obtained the same MAC Address using method 1 but somehow get different Addresses during offline vs online when using method 2, anyone can explain to me why? FYI my laptop only has one network card.

Method 2:

 public static string GetMACAddress2()
        {
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            String sMacAddress = string.Empty;
            foreach (NetworkInterface adapter in nics)
            {
                if (sMacAddress == String.Empty)// only return MAC Address from first card  
                {
                    sMacAddress = adapter.GetPhysicalAddress().ToString();
                }
            }
            return sMacAddress;
        }

My result:

Online:
Method1: C85B76FD53xx
Method2: 6A00E3D94Exx

Offline:
Method1: C85B76FD53xx
Method2: C85B76FD53xx

Thanks.

Ravi Saroch
  • 934
  • 2
  • 13
  • 28
Sylvester
  • 11
  • 1
  • in command / powershell prompt, run ```ipconfig /all``` see what adapters you have, you may have virtual adapters that disappear offline – Keith Nicholas Oct 15 '19 at 04:15
  • You want to *obtain MAC Address of the current PC*? The MAC address belongs to a device, a Network Interface (Card), in this case, not the PC. If you want a specific MAC address, also check the Network Interface name/identifier. Your machine will have more than one Network Interface, some of them will have a MAC address. The order in which the NICs are added to a collection is not relevant. WMI and the .Net class work differently. – Jimi Oct 15 '19 at 06:01

0 Answers0