我在同步“IP 地址和描述”时遇到问题。
目标是这样的:
获取 IP 地址和描述是什么?
例子:
| Atheros Azx1234 Wireless Adapter |
|192.168.1.55 |
但是结果不是我想象的那样……
这是我的代码随意尝试...
private void button1_Click(object sender, EventArgs e)
{
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
IPHostEntry host;
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (NetworkInterface adapter in interfaces)
{
foreach (IPAddress ip in host.AddressList)
{
if ((adapter.OperationalStatus.ToString() == "Up") && // I have a problem with this condition
(ip.AddressFamily == AddressFamily.InterNetwork))
{
MessageBox.Show(ip.ToString(), adapter.Description.ToString());
}
}
}
}
我该如何解决这个问题?