PDA

View Full Version : Getting Real IP address in ASP



AcidRaZor
19-04-2006, 08:31 AM
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?

AcidRaZor
19-04-2006, 08:53 AM
Request.ServerVariables("HTTP_X_FORWARDED_FOR")

Moederloos
19-04-2006, 08:55 AM
things like this make me appreciate PHP all the more!
1 minute on google gave me this:



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.

AcidRaZor
19-04-2006, 08:58 AM
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)