C# 是否在Windows Phone 8中查找所有可用IP?

C# 是否在Windows Phone 8中查找所有可用IP?,c#,windows-phone-8,ip-address,C#,Windows Phone 8,Ip Address,我正在试图找到一种方法来查看任何一台设备上的所有可用IP地址 这是我在Android上使用的: public String[] getLocalIpAddress() { ArrayList<String> addresses = new ArrayList<String>(); try { for (Enumeration<NetworkInterface> en = Net

我正在试图找到一种方法来查看任何一台设备上的所有可用IP地址

这是我在Android上使用的:

public String[] getLocalIpAddress()
    {          
        ArrayList<String> addresses = new ArrayList<String>();
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {    
                        addresses.add(inetAddress.getHostAddress().toString());
                    }
                 }
             }
         } catch (SocketException ex) {
             String LOG_TAG = null;
             Log.e(LOG_TAG, ex.toString());
         }
         return addresses.toArray(new String[0]);
    }
public字符串[]getLocalIpAddress()
{          
ArrayList地址=新的ArrayList();
试一试{
对于(枚举en=NetworkInterface.getNetworkInterfaces();en.hasMoreElements();){
NetworkInterface intf=en.nextElement();
对于(枚举Enumeration EnumipAddress=intf.getInetAddresses();EnumipAddress.hasMoreElements();){
InetAddress InetAddress=enumIpAddr.nextElement();
如果(!inetAddress.isLoopbackAddress()){
address.add(inetAddress.getHostAddress().toString());
}
}
}
}捕获(SocketException例外){
字符串LOG_TAG=null;
Log.e(Log_标记,例如toString());
}
返回地址.toArray(新字符串[0]);
}

谢谢

您可以在
System.Net.NetworkInformation
命名空间中使用
NetworkInterface.GetAllNetworkInterfaces()

List<IPAddress> ips = NetworkInterface.GetAllNetworkInterfaces()
              .Where(x => x.NetworkInterfaceType != NetworkInterfaceType.Loopback)
              .SelectMany(x => x.GetIPProperties().UnicastAddresses)
              .Select(x => x.Address)
              .ToList();

谢谢你,我要试一试!你知道我将如何用结果填充数组吗?我可以使用LongListViewer显示它们吗?GeetAllNetworkInterfaces()不适用于Windows应用商店应用程序。有什么解决办法吗?
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();