I just want to get the System IP address and display it on a UI.Can someone please tell the API to be used for the same
+3
A:
internal IPAddress[] GetIPAddresses()
{
string hostName = System.Net.Dns.GetHostName();
IPHostEntry ihe = System.Net.Dns.GetHostEntry(hostName);
return ihe.AddressList;
}
KristoferA - Huagati.com
2010-04-06 09:50:13
Thanks man .thats what i was looking for
Ravisha
2010-04-06 12:22:52
+6
A:
var address = Dns.GetHostAddresses(Dns.GetHostName())
.FirstOrDefault(addr => !IPAddress.IsLoopback(addr));
Console.WriteLine(address);
(this code excludes the local address 127.0.0.1)
Thomas Levesque
2010-04-06 09:50:48
You may want to change .First to .FirstOrDefault, in case the computer has no IP.
KristoferA - Huagati.com
2010-04-06 10:24:14