I'm building an application for personal use and I need to list all network interfaces' IP addresses and types.
I use the following code:
foreach (var networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{
foreach (var addressInfo in networkInterface.GetIPProperties().UnicastAddresses)
{
// Add the following string to a list and then display this list
var info = $"{addressInfo.Address}: {networkInterface.NetworkInterfaceType} ({Enum.GetName(typeof(NetworkInterfaceType), networkInterface.NetworkInterfaceType)})";
}
}
The code above works fine on Windows but when I build and run it on Android networkInterface.NetworkInterfaceType always returns 0 and Enum.GetName(typeof(NetworkInterfaceType), networkInterface.NetworkInterfaceType) returns an empty string.
This behavior can be reproduced in applications built with Unity and Xamarin (even though the application has all the required permissions granted).
from NetworkInterface.NetworkInterfaceType Property Always Returns 0 On Android
No comments:
Post a Comment