Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP (http://www.go4expert.com/articles/asp-tutorials/)
-   -   How to retrieve the TRUE IP address in ASP (http://www.go4expert.com/articles/retrieve-true-ip-address-asp-t285/)

pradeep 1May2005 22:10

How to retrieve the TRUE IP address in ASP
 
Request.ServerVariables("REMOTE_ADDR") can be used to retrieve the IP address of the client machine.

While clients connect internet via a proxy server, the above method only return the IP address of the proxy server, other than the REAL IP address of the client machine. In order to request the TRUE IP address of the client via the proxy server, you may use
Request.ServerVariables("HTTP_X_FORWARDED_FOR").

One more thing, if the client does not connect the internet via a proxy server, then Request.ServerVariables ("HTTP_X_FORWARDED_FOR") will return a null value. Therefore, you can use this method in your program like this:

Code: ASP

userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then
   userip = Request.ServerVariables("REMOTE_ADDR")
End if

i.e. If client connect the internet via a proxy server, we take the value returned by

HTTP_X_FORWARDED_FOR, otherwise we take the value returned by REMOTE_ADDR

raju123 28Oct2007 17:01

Re: How to retrieve the TRUE IP address in ASP
 
Thankx

raju123 28Oct2007 17:05

Re: How to retrieve the TRUE IP address in ASP
 
is any problem in Request.UserHostAddress.ToString()

sudamerica 7Nov2007 04:30

Re: How to retrieve the TRUE IP address in ASP
 
hi sorry iam new, where should i put all that?
thanks a lot

pradeep 7Nov2007 10:12

Re: How to retrieve the TRUE IP address in ASP
 
What's your objective?

urstop 19Nov2007 07:56

Re: How to retrieve the TRUE IP address in ASP
 
Thats a good point. If it is going to retreive the original IP, why do people use all these proxy sites to hide their traces? So, if we are going to use the SERVER VARIABLE specified by you, we will be knowing there true IPs, isin't it? Or is there a different way these proxy sites work?

pradeep 19Nov2007 10:11

Re: How to retrieve the TRUE IP address in ASP
 
There are two types of proxies transparent and anonymous, transparent server sends over the original IP, where anonymous hides the original IP, the above code will only work for a transparent proxy!

urstop 19Nov2007 14:14

Re: How to retrieve the TRUE IP address in ASP
 
Ok thanks, that clears up things. As a suggestion, it would be good to add this info about transparent and anonymous proxies in your original message.

dilipv 6Mar2008 13:16

Re: How to retrieve the TRUE IP address in ASP
 
Quote:

Originally Posted by pradeep
There are two types of proxies transparent and anonymous, transparent server sends over the original IP, where anonymous hides the original IP, the above code will only work for a transparent proxy!

Hi pradeep,

Can you help me to suggest how to use anonymous proxies. how to implement such proxies in asp.net application.

Thanks in advance.

Jitesh
programmer

gkumar 17Jun2009 16:45

Re: How to retrieve the TRUE IP address in ASP
 
This tutorial covers on fetching the exact client IP address. Here the author explains that using Request.ServerVariables("REMOTE_ADDR") can only bring the IP address of the proxy server. So the author finally decided to use...


All times are GMT +5.5. The time now is 04:03.