【发布时间】:2012-10-21 21:54:04
【问题描述】:
我在同步“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());
}
}
}
}
我该如何解决这个问题?
【问题讨论】:
-
我已经试过你的代码并且它正在工作,你能更详细地解释这个问题吗?
-
我认为您发布的代码没有问题。我已经设法从我系统上运行的每个网络设备获取我的本地 IP :)
-
当我们有多个互联网适配器时会出现问题..
-
查看“cmd > ipconfig /all”观察消息框会重复ip地址s
-
消息框只能预览您计算机的适配器
标签: c# networking ip-address