[C#] 纯文本查看 复制代码
using System.Net.NetworkInformation;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();//获取本地计算机上网络接口的对象
Console.WriteLine("适配器个数:" + adapters.Length);
Console.WriteLine();
foreach (NetworkInterface adapter in adapters)
{
Console.WriteLine("描述:" + adapter.Description);
Console.WriteLine("标识符:" + adapter.Id);
Console.WriteLine("名称:" + adapter.Name);
Console.WriteLine("类型:" + adapter.NetworkInterfaceType);
Console.WriteLine("速度:" + adapter.Speed * 0.001 * 0.001 + "M");
Console.WriteLine("操作状态:" + adapter.OperationalStatus);
Console.WriteLine("MAC 地址:" + adapter.GetPhysicalAddress());
// 格式化显示MAC地址
PhysicalAddress pa = adapter.GetPhysicalAddress();//获取适配器的媒体访问(MAC)地址
byte[] bytes = pa.GetAddressBytes();//返回当前实例的地址
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
sb.Append(bytes[i].ToString("X2"));//以十六进制格式化
if (i != bytes.Length - 1)
{
sb.Append("-");
}
}
Console.WriteLine("MAC 地址:" + sb);
Console.WriteLine();
}
Console.ReadKey();
}
}
}
自己根据方法找找,在对象里有的本来就有名称,而只不过你找的方法只取了ID,例如我上面发的 |