Forum Moderators: open

Message Too Old, No Replies

ASP - IP Address Detection

Looking for some quick information...

         

Eric_Lander

3:47 pm on Nov 1, 2001 (gmt 0)

10+ Year Member



I need to add some code to an existing ASP script that will retrieve the IP Address of the browsing visitor, then choose whether or not to display information.

So, my question is this:
"How can I retrieve the IP Address from the browser requesting the page?" - Knowing that I am not a guru by any means, I'm sure this isn't all that tough.

All I will do is set a declared variable to that value, then process the information as needed. But how do I acquire it?

Any help, as always, is much appreciated! Thanks!
~Eric

joshie76

3:50 pm on Nov 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Request.Servervariables("REMOTE_HOST") should get it.

Eric_Lander

4:21 pm on Nov 1, 2001 (gmt 0)

10+ Year Member



Great josh! THanks!

Xoc

6:53 pm on Nov 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This code, BTW, will retrieve all of the information that you can get from the IIS server variables. Place it into an ASP file, then browse to it.

<table BORDER="1">
<th COLSPAN="2">ServerVariables</th>
<%
Dim var
For Each var in Request.ServerVariables
Call Response.Write("<TR>")
Call Response.Write("<TD><B>" & var & "</B>:</TD>")
Call Response.Write("<TD>" & Request.ServerVariables(var) _
& "</TD>")
Call Response.Write("</TR>")
Next
%>
</table>

Will

6:15 pm on Nov 2, 2001 (gmt 0)



Try using "REMOTE_ADDR" rather than "REMOTE_HOST", for two reasons.

1) "REMOTE_HOST" willl return the name of the host machine if your server is set up to perform reverse DNS lookup when the site is accessed.

2) REMOTE_HOST defaults to the value of REMOTE_ADDR if no hostname information is available. Therefore you will achieve a performance gain using the latter variable (admittedly a very small one, but it all helps, especially as the site gets busier :))

websurprise

1:01 pm on Feb 12, 2002 (gmt 0)



I have the Remote Address from a FormMail form a surfer filled out. With the IP address, what tool can I use to find out what area of the world they are from? Thanks.

rpking

1:48 pm on Feb 12, 2002 (gmt 0)