Jergason Jergason - 1 year ago 101
ASP.NET (C#) Question

Getting the IP address of server in ASP.NET?

How do I get the IP address of the server that calls my ASP.NET page? I have seen stuff about a Response object, but am very new at c#. Thanks a ton.

Answer Source

This should work:

 //this gets the ip address of the server pc

  public string GetIPAddress()
     IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); // `Dns.Resolve()` method is deprecated.
     IPAddress ipAddress = ipHostInfo.AddressList[0];

     return ipAddress.ToString();


 //while this gets the ip address of the visitor making the call

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download