我在同步「IP地址和描述」時遇到了問題。使用C獲取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 :) –
當我們有多個Internet適配器時會發生問題.. –