I am trying to Get IP Address of Current Machine in Xamarin.Mac. I am using this C# Code and it's working in Windows very well but for Xamarin.But on Mac it throws an
System.Net.Sockets.SocketException
.
Here is the code I'm Using:
public override void AwakeFromNib()
{
base.AwakeFromNib();
try
{
IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName());
combo_box.UsesDataSource = true;
combo_box.Add(new NSString("127.0.0.1"));
foreach (IPAddress item in IPHost.AddressList)
{
combo_box.Add(new NSString(item.ToString()));
}
Clients clt = GetLatestClient();
if (!String.IsNullOrEmpty(clt.ServerIP) && !String.IsNullOrEmpty(clt.ipadd))
{
ServerIpAddress = clt.ServerIP;
IpAddressVal = clt.ipadd;
//ClientForm serverMaster = new ClientForm();
//serverMaster.Show();
//BeginInvoke(new MethodInvoker(Hide));
}
}
Here is exception that is being thrown:
could not resolve host 'host name'