c#获取网卡信息
在C#中,可以使用NetworkInterface类来获取网卡信息。下面是一个示例代码,可以获取所有网卡的名称和MAC地址:
using System;
using System.Net.NetworkInformation;
class Program
{
static void Main()
{
NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface networkInterface in networkInterfaces)
{
Console.WriteLine("名称: " + networkInterface.Name);
Console.WriteLine("MAC地址: " + networkInterface.GetPhysicalAddress());
Console.WriteLine();
}
Console.ReadLine();
}
}
这段代码首先使用NetworkInterface.GetAllNetworkInterfaces()方法获取所有网卡的信息,然后使用foreach循环遍历每个网卡,输出名称和MAC地址。
可以根据需要自定义输出网卡的其他信息,比如IP地址、子网掩码等。参考NetworkInterface类的其他方法和属性可以获取更多的网卡信息
原文地址: https://www.cveoy.top/t/topic/hIF6 著作权归作者所有。请勿转载和采集!