Home > ASP.NET 2.0, C# > Getting Visitor’s IP Address and Server’s IP Address

Getting Visitor’s IP Address and Server’s IP Address

Thursday, 24 April, 2008 Leave a comment Go to comments

Getting Visitors IP Address:

There are two ways, either by using:
HttpContext.Current.Request.UserHostAddress;
or
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

The Following Line will get the IP Address of the machine instead of Proxy’s IP

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

Getting Server’s IP address:

string strHostName = Dns.GetHostName ();
IPHostEntry ipEntry = Dns.GetHostByName (strHostName);
IPAddress [ ] addr = ipEntry.AddressList;
for(int i=0;i< addr.Length;i++)
{
lblServerIP.Text=lblServerIP.Text+"The Server IP address is"+addr[i].ToString()+"\n";
}

Categories: ASP.NET 2.0, C# Tags: ,
  1. Thursday, 24 April, 2008 at 4:37 pm

    namespace for IPHostEntry: System.Net;

  2. Thursday, 24 April, 2008 at 4:43 pm
  3. Thursday, 24 April, 2008 at 7:20 pm

    Өзім әлі тексеріп көрген жоқпын 😉

  4. Sunday, 20 November, 2016 at 4:00 am

    It’s not my first time to go to see this site, i am browsing this web site dailly and take nice data from here every day.

  1. No trackbacks yet.

Leave a comment