弄电脑的MAC地址地址、电脑、MAC

由网友(猎物)分享简介:我想accesss使用C#的计算机的MAC地址。我使用了下列code访问MAC地址,但有这code一些问题。 I want to accesss the mac address of the computer using c#. I have used the following code to access mac...

我想accesss使用C#的计算机的MAC地址。我使用了下列code访问MAC地址,但有这code一些问题。

I want to accesss the mac address of the computer using c#. I have used the following code to access mac address but there is some issue in this code.

code 1

foreach( NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces() )
{
    if( nic.OperationalStatus == OperationalStatus.Up )
    {
        Console.WriteLine( nic.GetPhysicalAddress().ToString() );
        checkMAC = nic.GetPhysicalAddress().ToString();
        break;
    }
}

code 2

 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(":", "");

在第一个code当我们从网络连接断开,那么它将返回空的MAC地址。第二code返回时网络适配器连接ID断开的MAC地址,但是,当我们disbled网络连接或删除计算机的IP地址,然后它会返回空的MAC地址。

In first code when we disconnected from network connection then it will return null mac address . second code return the mac address when network adapter connection id disconnected But when we disbled the network connection or remove the IP address of the computer then it will return the null mac address .

如何得到MAC地址时,网络连接系统,禁用,有一个分配给PC或网络连接没有IP地址,断开连接?

How to get the mac address when network connnection disabled, there is no IP address assigned to the PC or network connection disconnected?

推荐答案

当您禁用网络适配器,你不能访问它在所有 - 这是因为如果没有安装,这就是为什么你不这样做看到一个MAC地址。

When you disable your network adapter, you can't access it at all - it is as if it isn't installed, which is why you don't see a MAC address.

编辑:说明:

一个MAC地址属于一个网络适配器。如果你有3个适配器,你有3个MAC地址。如果没有适配器,你有没有MAC地址。

A MAC address belongs to a network adapter. If you have 3 adapters you have 3 MAC addresses. If you have no adapters, you have no MAC address.

阅读全文

相关推荐

最新文章