如何检测网络适配器wi-fi或以太网C#? [英] How to detect whether the network adapter wi-fi or ethernet C# ?
本文介绍了如何检测网络适配器wi-fi或以太网C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在表格中我有comboBox1,当我点击comboBox1然后选择一个网络适配器并且它可以工作。
当我选择网络适配器时,我想:
,因此Label1.Text将是:
Wi-Fi或以太网。 />
到目前为止的代码低于(并且有效)。
请帮忙。谢谢。
我尝试了什么:
Hello everyone,
In the form I have comboBox1, when I click on comboBox1 then selects a network adapter and it works.
I would like to:
when I select a network adapter, as a result in the "Label1.Text" will be:
Wi-Fi or Ethernet.
Code that has so far is below (and it works).
Please Help. Thank you.
What I have tried:
private void Form1_Load(object sender, EventArgs e)
{
ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapter Where AdapterType='Ethernet 802.3'");
foreach (ManagementObject mo in mos.Get())
{
comboBox1.Items.Add(mo["Name"].ToString());
}
}
推荐答案
尝试使用NetworkInterfaceType属性:
Try the NetworkInterfaceType property:
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.OperationalStatus == OperationalStatus.Up)
{
Console.WriteLine(ni.NetworkInterfaceType.ToString());
}
}
Thanks, but this code detects the type of network adapter that is active, and I want to detect the type of network adapter what I select it.
example:
If you have two adapters (Wi-Fi and Ethernet), and Wi-Fi is active and the Ethernet is not active, and if I select Ethernet to get the result = Wireless80211.
or
if the active Ethernet and Wi-Fi is not active, and I select Wi-Fi as a result get = Ethernet.
这篇关于如何检测网络适配器wi-fi或以太网C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文