问题

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

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐