Retrieve IP address of device

c#, ip-address, xamarin, xamarin.android

Solution

From the Xamarin forums

Java.Util.IEnumeration networkInterfaces = NetworkInterface.NetworkInterfaces;

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

Problem

I am using Xamarin.Android and wrote the following code: ``` public TextView text; text = FindViewById<TextView>(Resource.Id.viewIP); foreach (IPAddress adress in Dns.GetHostAddresses(Dns.GetHostName())) { text.Text = "IP Adress: " + adress; } ``` However, when I open the application it shuts down immediately. Am I using the correct way of getting the IP address' of the device?

Original source

Related problems