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";
}

Advertisements
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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: