GetAllNetworkInterfaces()抛出exception

在Mono for Android中,我试图在本地网络中获取设备的所有IP地址。

我不介意环回,但我对调用DNS不感兴趣。

最好的方式似乎是打电话……

using System.Net.NetworkInformation; NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); 

…除了它抛出……

System.EntryPointNotFoundException:getifaddrs

有什么建议?

不幸的是,这是Mono for Android中的一个已知错误。 错误报告可在此处获得 。

如果您只使用Mono for Android,您可以尝试使用此代码获取每个IP:

 Java.Util.IEnumeration networkInterfaces = NetworkInterface.NetworkInterfaces; while(networkInterfaces.HasMoreElements) { Java.Net.NetworkInterface netInterface = (Java.Net.NetworkInterface)networkInterfaces.NextElement(); Console.WriteLine(netInterface.ToString()); } 

输出:

[10] [1] [/ :: 1%1%1] [/ 127.0.0.1]
[dummy0] [2]
[sit0] [3]
[ip6tnl0] [4]
[为wlan0] [5] [/ FE80 :: 8e77:12FF:fe5a:6052%为wlan0%5] [/ 192.168.100.135]
[ppp0的] [6] [/ 10.0.0.1]