GetAllNetworkInterfaces() throws exception

假装没事ソ 提交于 2020-01-03 17:12:10

问题


In Mono for Android I'm trying to obtain all the IP addresses for my device within the local network.

I don't mind loopbacks but I'm not interested in calling DNS.

The best way seems to be calling...

using System.Net.NetworkInformation;

NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();

...except it throws...

System.EntryPointNotFoundException: getifaddrs

Any suggestions?


回答1:


Unfortunately this is a known bug in Mono for Android. The bug report is available here.




回答2:


If you only use Mono for Android, you can try this code to obtain every IP:

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

Output:

[lo][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]



来源:https://stackoverflow.com/questions/9973980/getallnetworkinterfaces-throws-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!