Search code examples
c#listnetworkingwindows-phone-8ip

Viewing all available IPs in a Windows Phone app?


I have previously asked this question but ran into difficulties in implementing the given answer.

I was told that the following code would do what I required (that was list all available IPs on the device that was running my app and display them as a list, allowing the user to choose one).

var  ips = NetworkInterface.GetAllNetworkInterfaces()
           .Where(inf => inf.NetworkInterfaceType != NetworkInterfaceType.Loopback)
           .Where(inf => inf.OperationalStatus == OperationalStatus.Up)
           .Select(x => new{
                name = x.Name,
                ips = x.GetIPProperties().UnicastAddresses.Select(y=>y.Address)
                      .ToList()
           })
           .ToList();

It now turns out most of this is not available to Windows Phone or Windows Store users.

I think what I need lies in the Microsoft.Phone.Net.NetworkInformation namespace but I can't pinpoint the exact method I'd need.

I do the same in Android and Apple which is fairly straightforward. An example of the Apple view is below:

enter image description here


Solution

  • using Windows.Networking.Connectivity;

    var ips = NetworkInformation.GetHostNames()
                .Where(x => x.IPInformation != null)
                .Select(x => x.DisplayName)
                .ToList();