System.Net.NetworkInformation下的
1:NetworkInterface类,提供网络适配器的配置和统计信息。
可以通过它检测本机配置了多少网卡,哪些网络连接可用,获得网卡的MAC地址和速度等。
GetAllNetworkInterfaces 方法返回一个数组,对于本地计算机上的每个网络接口,该数组中都包含一个此类的实例。
提供有关支持 Internet 协议版本 4 (IPv4) 或 Internet 协议版本 6 (IPv6) 的网络接口的信息。
GetIPProperties 方法返回。
GetIPv6Properties 方法返回的对象
1 void Start () { 2 //网卡信息类 3 NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); 4 foreach (NetworkInterface adap in adapters) 5 { 6 Debug.Log("CardName::" + adap.Name + " /Speed::" + adap.Speed + " /MAC::" + BitConverter.ToString(adap.GetPhysicalAddress().GetAddressBytes())); 7 IPInterfaceProperties ipProperties = adap.GetIPProperties(); 8 GatewayIPAddressInformationCollection gateways = ipProperties.GatewayAddresses; 9 foreach (var tmp in gateways) 10 { 11 Debug.Log("Gateway>>>"+tmp.Address); 12 } 13 IPAddressCollection dnsAddress = ipProperties.DnsAddresses; 14 foreach (IPAddress tmp in dnsAddress) 15 { 16 Debug.Log("DNS>>>" + BitConverter.ToString(tmp.GetAddressBytes())); 17 } 18 } 19 }
//output
NetworkInterface>>> https://msdn.microsoft.com/zh-cn/library/system.net.networkinformation.networkinterface%28v=vs.110%29.aspx
IPInterfaceProperties>>> https://msdn.microsoft.com/zh-cn/library/system.net.networkinformation.ipinterfaceproperties%28v=vs.110%29.aspx