Reputation: 31
I am getting the IP address list using the following code :
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
I am getting the proper IP address when device connected to a profile. But when we connect the device to PC with USB, IP address is getting changed. We want to display only the WLAN IP address all the time in our application.
Is there any API/function which can give only WLAN IP address instead all ? or Is there any way to differentiate the WLAN IP from the list of IP addresses return from the above source code ?
Upvotes: 3
Views: 1461
Reputation: 144
Maybe somthing like:
var address = NetworkInterface
.GetAllNetworkInterfaces()
.Where(i => i.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
.SelectMany(i => i.GetIPProperties().UnicastAddresses)
.Where(a => a.Address.AddressFamily == AddressFamily.InterNetwork)
.Select(a => a.Address.ToString())
.ToList();
From: Github
Found: Stackoverflow
Upvotes: 2