Getting Real IP address in ASP

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Reaction score
13
Hi guys,

ADSL users usually proxy through for international access (Ala Telkom) giving ip addresses like 198.54.202.234

Now, Server.RequestVariables("Remote_ADDR") gives me that IP, which can change to something else at a drop of a hat.

I need the 165.*.*.* IP address to do my security encryption correctly. Anyone have an idea how to achieve this?
 
things like this make me appreciate PHP all the more!
1 minute on google gave me this:

PHP:
if  (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],',')) {
       $tmp +=  explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
   } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
       $tmp[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
   }
   $tmp[] = $_SERVER['REMOTE_ADDR'];
print_r ($tmp);

any how, depending on your skill set, run this php code and insert into a database, and then retrieve in ASP should work. Bear in mind though, that the articles I saw state that the header can be spoofed.


more @
http://www.php.net/getenv


EDIT: although, ASP should have a similar call, just need to look up the syntax for "HTTP_X_FORWARDED_FOR" in ASP.
 
Thanks, your PHP code does the same as this :

Dim arr

arr = Request.ServerVariables("HTTP_X_FORWARDED_FOR").Split(",")
Response.Write arr(0)

Well, thats without checking if there's a "," in the return value and if there is a return value in the first place [replaced by remote_addr if there is none] (like your PHP code)
 
Top
Sign up to the MyBroadband newsletter
X