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,093
  • 9
  • 38
  • 64

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
  • 278,830
  • 63
  • 599
  • 738
3
internal IPAddress[] GetIPAddresses()
{
    string hostName = System.Net.Dns.GetHostName();
    IPHostEntry ihe = System.Net.Dns.GetHostEntry(hostName);
    return ihe.AddressList;
}
KristoferA
  • 12,067
  • 1
  • 39
  • 62