[2008] ASP.NET (VB) - How to retreive a client's IP

  • Thread starter Thread starter Doken13
  • Start date Start date
D

Doken13

I got an intranet web site and there is a proxy on the network.
I want to retreive a client's IP, how could I get it ?
 
Some proxies report in a request's header the actual client IP address.
There are 2 or 3 standard headers. x-forwarded-for is one of them

But some proxies do not do it. Those proxies called anonymous proxies by the
way.

George.
 
Doken13, here's sample code to retrieve either a real client IP
or a proxy's IP...and determine which is which :

// HTTP_VIA is not null if there's a proxy between your server and the client
if(Context.Request.ServerVariables["HTTP_VIA"]!=null)

{
// So, this code returns the client's real IP
ip=Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
// not using proxy or can't get the Client IP
//doesn't get the Client IP, but returns proxy IP
ip=Context.Request.ServerVariables["REMOTE_ADDR"].ToString();
}

As George says, you can not always get the Client IP through a proxy because
either a proxy will not send the client IP to you or a client can also be prevented
from sending its IP by the use of "header_access deny".
 
Back
Top