Find a visitor's IP Address with ASP

Do you want to know the IP address of a visitor? This can be useful for many reasons, such as tracking site usage or blocking access to specific people. Here's how you can find it.
Level: Beginner

In an ASP page, within the ASP tags, , you can retrieve the IP address of a user through the ServerVariables collection of the Request object. To do this, you use the code Request.ServerVariables("REMOTE_ADDR").

Display The IP Address
So, if you want to display the IP Address to the user then the following page will suffice:

Exploring Request.ServerVariables
You might be wondering what other information you can get from Request.ServerVariables, well you can find out with the following script which displays all the variables in it along with their values if set, in a HTML table:
<%@language="VBScript"%>
<table border="1">
<tr><th>Variable</th><th>Value</th></tr>
<%
Dim variable
For Each variable In Request.ServerVariables
   Response.Write "<tr><td>" & variable & "</td>"
   Response.Write "<td>" & Request.ServerVariables(variable) & "</td></tr>"
Next
%>
</table>
vdhri.net is a website dedicated to providing free lessons and tutorials in many programming languages.