Find a visitor’s IP Address in ASP
Published 2 years, 12 months ago in ASP and ASP BasicsDo 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.
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:
-
<%@language="VBScript"%>
-
<%
-
Response.Write "Hello! Your IP Address is: " & Request.ServerVariables("REMOTE_ADDR")
-
%>
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>
Improving the find IP code
Finally, the following code works harder to find the true IP of the user by checking to see if the visitor is using a proxy:
-
Function UserIP()
-
’ This returns the True IP of the client calling the requested page
-
’ Checks to see if HTTP_X_FORWARDED_FOR has a value then the client is operating via a proxy
-
UserIP = Request.ServerVariables ( "HTTP_X_FORWARDED_FOR" )
-
If UserIP = "" Then
-
UserIP = Request.ServerVariables ( "REMOTE_ADDR" )
-
End if
-
End Function
If you have a website, consider joining the Money4Banners advertising network. They will pay you £10 + £5 each month for displaying a small advert on three of your pages, regardless of traffic. American webmasters are welcome, and since £10 == $20, you make more!
8 Responses to “Find a visitor’s IP Address in ASP”
Leave a Reply
You must log in to post a comment.
Search
Categories
- ASP (3)
- ASP Basics (3)
- Blogs (2)
- C# (1)
- Firefox (1)
- Flash (1)
- Google (6)
- Hacks (3)
- Java (1)
- PHP (12)
- Basics (8)
- Files (1)
- Image Handling (3)
- Puzzles (1)
- Ruby (1)
- Tips (10)
- Web Hosting (3)
- Web Hosting Articles (1)
- Web Hosting News (2)
- Windows (6)
- Wordpress (2)
Related Entries
- Find a visitor's IP Address with PHP
- How to Find the Current URL in ASP
- How to use the QueryString in ASP
- PHP
- Web Hosting Terminology
- How to Access a Page in Google's Cache
- Hide a hard drive from My Computer
- How to Find the Current URL with PHP
- Use Google to define words
- How to find the SHA1 hash of a string in Ruby
Helped a LOT! Thanks very much!
How Can I transfer this IP Address to a Log File in My HostMachine….
Hi there,
I have a problem with finding out the real IP of the visitor. Looks that the simple code:
Request.ServerVariables(”REMOTE_ADDR”)
is not working and I always get the IP of the server instead.
Do you have any idea why?
Thanks,
Radu
Dear Radu and All,
I do have same problem with you which Request.ServerVariables(”REMOTE_ADDR”)
is always return me the server IP itself.
May i know that do you found out the solution alreday?
Mind to share what is the solution?
Thanks,
Jensen
i was wounderin gif anybody can tell me. i have chat system i want to place this code in guest table . if i want to block their ip i can do . is there anyone can help me how to store visitiros ip address in data base then i be able to block or give them access to use certain page?
help will be appreciated
thnx alot
hi
i want source code to find visitor ip address other website
example :
get visitor ip www.discomoose.org
I want to source code in vb.net or c# to find out the IP Address of other website visitor.
Thanks
Rajeev