目前,我正在获取接口设备的IP地址,子网和默认网关('无线网络连接')。这在接口连接时工作正常,但是,当没有连接时,尽管仍然在接口设备上静态设置并且可以使用netsh interface ip show address "Wireless Network Connection"
最好我希望避免使用netsh
来解析字符串以在没有连接的情况下获取这些值。有没有办法在没有连接的无线接口上获取这些静态值?
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface f in adapters)
{
if (f.NetworkInterfaceType != NetworkInterfaceType.Loopback
&& f.NetworkInterfaceType != NetworkInterfaceType.Tunnel
&& f.Name == "Wireless Network Connection")
{
IPInterfaceProperties ipInterface = f.GetIPProperties();
foreach (UnicastIPAddressInformation unicastAddress in ipInterface.UnicastAddresses)
{
textBox1.Text = unicastAddress.Address.ToString();
textBox2.Text = unicastAddress.IPv4Mask.ToString();
}
foreach (GatewayIPAddressInformation d in f.GetIPProperties().GatewayAddresses)
{
textBox3.Text = (d.Address.ToString());
}
}
}