如何获取所有网络适配器的列表? [英] How to get list of all network adapters?
本文介绍了如何获取所有网络适配器的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码仅检测已连接的适配器,但我需要全部:
foreach (NetworkInterface nic < span class =code-keyword> in NetworkInterface..GetAllNetworkInterfaces())
{
if (nic.NetworkInterfaceType = = NetworkInterfaceType.Ppp)
{
comboBox1.Items.Add(nic.Name);
}
}
请帮助。
解决方案
您可以使用该方法System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
:
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx [ ^ ]。< br $>
班级System.Net.NetworkInformation.NetworkInterface
具有属性名称
:
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.aspx [ ^ ],
http:// msdn .microsoft.com / zh-cn / library / system.net.networkinformation.networkinterface.name.aspx [ ^ ]。
-SA
This code detects only connected adapters, but I need all:
foreach (NetworkInterface nic in NetworkInterface..GetAllNetworkInterfaces() )
{
if (nic.NetworkInterfaceType == NetworkInterfaceType.Ppp)
{
comboBox1.Items.Add(nic.Name);
}
}
Please help.
解决方案
You can use the methodSystem.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
:
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx[^].
[EDIT]
The classSystem.Net.NetworkInformation.NetworkInterface
has the propertyName
:
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.name.aspx[^].
—SA
这篇关于如何获取所有网络适配器的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文