如何获取无线(媒体断开连接)首选网络的静态IP地址信息

时间:2015-01-22 22:31:31

标签: c# networking wireless

目前,我正在获取接口设备的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());
        }
    }
}

0 个答案:

没有答案