1

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

Ravisha
  • 3,261
  • 9
  • 39
  • 66

2 Answers2

7
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
  • 286,951
  • 70
  • 623
  • 758
3
internal IPAddress[] GetIPAddresses()
{
    string hostName = System.Net.Dns.GetHostName();
    IPHostEntry ihe = System.Net.Dns.GetHostEntry(hostName);
    return ihe.AddressList;
}
KristoferA
  • 12,287
  • 1
  • 40
  • 62