pooja k p
pooja k p

Reputation: 31

How to get WLAN IP address?

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

Answers (1)

Mojack
Mojack

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

Related Questions