jeudi 22 janvier 2015

How to get static IP address information of wireless (media disconnected) preferred network


Vote count:

0




Currently I am getting the IP address, subnet and default gateway of my interface device ('Wireless Network Connection'). This works fine when the interface has connection, however, when there is no connection, these values no longer output despite still being set statically on the interface device and retrievable using netsh interface ip show address "Wireless Network Connection"


Preferably I would like to avoid having to use netsh in order to parse string to get these values in the case of no connectivity. Is there any way to get these static values on a Wireless interface that does not have a connection?



NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface f in adapters)
{
if (f.NetworkInterfaceType != NetworkInterfaceType.Loopback)
if (f.NetworkInterfaceType != NetworkInterfaceType.Tunnel)
if (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());
}
}
}


asked 1 min ago







How to get static IP address information of wireless (media disconnected) preferred network

Aucun commentaire:

Enregistrer un commentaire