tags:

views:

81

answers:

2

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
Thanks man .thats what i was looking for
Ravisha
+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
+1 for linq version
Mikael Svenson
You may want to change .First to .FirstOrDefault, in case the computer has no IP.
KristoferA - Huagati.com
@Kristofer, yes, good point, I fixed it. Thanks !
Thomas Levesque