Archive

Posts Tagged ‘IP Addres’

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

Thursday, 24 April, 2008 4 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: ,