C # Get Computer 's MAC address" OFFLINE"

Czy Jest jakiś sposób na uzyskanie adresu mac komputera, gdy nie ma połączenia z Internetem w c#? Jestem w stanie uzyskać, gdy mam połączenie, ale nie mogę uzyskać, gdy jestem offline. Ale zdecydowanie potrzebuję adresu mac do mojej pracy.

Mój kod online;

var macAddr =
      (from nic in NetworkInterface.GetAllNetworkInterfaces()
       where nic.OperationalStatus == OperationalStatus.Up
       select nic.GetPhysicalAddress().ToString()).FirstOrDefault();
Author: Mehmet Ince, 2013-04-03

2 answers

Z WMI:

public static string GetMACAddress1()
{
    ManagementObjectSearcher objMOS = new ManagementObjectSearcher("Select * FROM Win32_NetworkAdapterConfiguration");
    ManagementObjectCollection objMOC = objMOS.Get();
    string macAddress = String.Empty;
    foreach (ManagementObject objMO in objMOC)
    {
        object tempMacAddrObj = objMO["MacAddress"];

        if (tempMacAddrObj == null) //Skip objects without a MACAddress
        {
            continue;
        }
        if (macAddress == String.Empty) // only return MAC Address from first card that has a MAC Address
        {
            macAddress = tempMacAddrObj.ToString();              
        }
        objMO.Dispose();
    }
    macAddress = macAddress.Replace(":", "");
    return macAddress;
}

Od System.Net przestrzeń nazw:

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  
        {
            //IPInterfaceProperties properties = adapter.GetIPProperties(); Line is not required
            sMacAddress = adapter.GetPhysicalAddress().ToString();
        }
    } return sMacAddress;
}

Lekko zmodyfikowany z Jak uzyskać adres MAC systemu - C-Sharp Corner

 25
Author: jordanhill123,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-20 20:16:01

Możesz użyć WMI w C #(System.Management), aby uzyskać listę Win32_NetworkAdapter, która zawiera właściwość MACAddress.

Http://msdn.microsoft.com/en-gb/library/windows/desktop/aa394216 (v=vs.85). aspx

 3
Author: PhonicUK,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-03 09:46:58