开发者

Get MAC Address when network adapter is disabled?

Is there any way i can retrieve MAC Address when Network Adapter is disable开发者_JAVA技巧d in .net?

Thanks in advance,


It is not possible to get the MAC address of an adapter which is disabled: this is because getting the MAC address requires querying the driver, and the driver for a disabled adapter is not loaded (source).

You can, however get the MAC address of an adapter which is not currently connected.

The WMI route is no good here, because it shows the MAC address as null for adapters which are not connected. The good news is that the NetworkInterface.GetAllNetworkInterfaces() route works just fine:

// using System.Net.NetworkInformation;
var nics = NetworkInterface.GetAllNetworkInterfaces();

// pick your NIC!
var selectedNic = nics.First();

var macAddress = selectedNic.GetPhysicalAddress().ToString();


Refer this link.

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.physicaladdress.aspx

The example here displays physical address of all interface irrespective of their operational stage. HTH.


You can use WMI:

public static string GetMACAddress()
    {
        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
            {
                MACAddress= mo["MacAddress"].ToString() ;
            }
            mo.Dispose();
        }

        return MACAddress;
    }


Using MS PowerShell command get-NetAdapter one can get the disabled network adapter's MAC Address.

More info at get-NetAdapter

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜