<Blog:SatheeshBabu LiveAt="India"></Blog>    CodeDigest.com Latest 

Articles

         

Friday, November 11, 2005

Getting Visitor's IP Address and Server's IP Address
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";

}


Demo

Regards,
Satheesh

www.codedigest.com

0 Comments:

Post a Comment

<< Home