当前位置:编程学习 > C#/ASP.NET >>

C# 获取mac

我机子有两个网卡 C# 怎么获取正在对外使用的网卡的mac >>>?????
   
 System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection MOC=mc.GetInstances();
            string s = string.Empty;
            foreach (ManagementObject mo in MOC)
            {
                if (mo["IPEnabled"].ToString() == "True")
                {
                    s += mo["MacAddress"].ToString()+"\t\t\t";
                }
            }
这个可以获取两个mac 。。。。。。。。。。。。。???
--------------------编程问答-------------------- 没试过二个的。

关注。 --------------------编程问答--------------------

public static void ShowNetworkInte易做图ces()
    {//MSDN上的例子,获取MAC地址
        IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
        NetworkInte易做图ce[] nics = NetworkInte易做图ce.GetAllNetworkInte易做图ces();
        Console.WriteLine("Inte易做图ce information for {0}.{1}     ",
                computerProperties.HostName, computerProperties.DomainName);
        if (nics == null || nics.Length < 1)
        {
            Console.WriteLine("  No network inte易做图ces found.");
            return;
        }

        Console.WriteLine("  Number of inte易做图ces .................... : {0}", nics.Length);
        foreach (NetworkInte易做图ce adapter in nics)
        {
            IPInte易做图ceProperties properties = adapter.GetIPProperties(); //  .GetIPInte易做图ceProperties();
            Console.WriteLine();
            Console.WriteLine(adapter.Description);
            Console.WriteLine(String.Empty.PadLeft(adapter.Description.Length, '='));
            Console.WriteLine("  Inte易做图ce type .......................... : {0}", adapter.NetworkInte易做图ceType);
            Console.Write("  Physical address ........................ : ");
            PhysicalAddress address = adapter.GetPhysicalAddress();
            byte[] bytes = address.GetAddressBytes();
            for (int i = 0; i < bytes.Length; i++)
            {
                // Display the physical address in hexadecimal.
                Console.Write("{0}", bytes[i].ToString("X2"));
                // Insert a hyphen after each byte, unless we are at the end of the 
                // address.
                if (i != bytes.Length - 1)
                {
                    Console.Write("-");
                }
            }
            Console.WriteLine();
        }
    }
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,