This is the code i've been using for months with zero issues. It returns the
first IP4 address, which always seems to be the correct address.
public static IPAddress GetIPAddress()
{
IPAddress[] availableAddresses =
Dns.GetHostAddresses(Dns.GetHostName() + ".local");
IPAddress activeAddress = null;
foreach (IPAddress ip in availableAddresses)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
activeAddress = ip;
break;
}
}
return activeAddress;
}
public static IPAddress GetIPAddress(string hostName)
{
IPAddress[] availableAddresses = Dns.GetHostAddresses(hostName);
IPAddress activeAddress = null;
foreach (IPAddress ip in availableAddresses)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
activeAddress = ip;
break;
}
}
return activeAddress;
}
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/Dns-GetHostEntry-in-MonoTouch-tp4656219p4656227.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch