ASPProtect ( Click Here For More Details !!! )
Return To Home Page - Link to "The Wanker" - Contact Us


Return To Home Page

Retrieve a Users IP Address



Using ASP or Active Server Pages it is actually quite easy to retrieve a users IP Address.

REMOTE_ADDR and HTTP_X_FORWARDED_FOR are the two server variables we are interested in in order to attempt to capture a users IP address.

Many people simply grab the IP Address like so.

<%
Dim UserIPAddress
UserIPAddress = Request.ServerVariables("REMOTE_ADDR")
%>


This however is a better way to do it.

<%
Dim UserIPAddress
UserIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If UserIPAddress = "" Then
  UserIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
%>


The reason we look for the HTTP_X_FORWARDED_FOR value 1st is because of proxy servers and things of that nature as many users are behind one. If that value is not there we just grab the
REMOTE_ADDR. Even by doing this there are going to be times when we do not get an IP Address or what we get is not accurate. There really is not anything you can do about that.

Regarding there
server variables you can always loop through them as well and show MOST of them which is very helpful when testing.

<table border="1" width="500" style="border-collapse: collapse">
<%
For each item in Request.ServerVariables
   Response.Write("<tr><td>" & item & "</td><td>")
   Response.Write(Request.ServerVariables(item))
   Response.Write("</td></tr>" & vbCrLf)
Next
%>

</table>

Your going to see a lot of server information you never knew existed when doing that.
Similar to this below.
 
APPL_MD_PATH /LM/W3SVC/1/ROOT
APPL_PHYSICAL_PATH c:\inetpub\wwwroot\
AUTH_PASSWORD  
AUTH_TYPE  
AUTH_USER  
CERT_COOKIE  
CERT_FLAGS  
CERT_ISSUER  
CERT_KEYSIZE  
CERT_SECRETKEYSIZE  
CERT_SERIALNUMBER  
CERT_SERVER_ISSUER  
CERT_SERVER_SUBJECT  
CERT_SUBJECT  
CONTENT_LENGTH 0
CONTENT_TYPE  
GATEWAY_INTERFACE CGI/1.1
HTTPS off
HTTPS_KEYSIZE  
HTTPS_SECRETKEYSIZE  
HTTPS_SERVER_ISSUER  
HTTPS_SERVER_SUBJECT  
INSTANCE_ID 1
INSTANCE_META_PATH /LM/W3SVC/1
LOCAL_ADDR 192.168.1.100
LOGON_USER  
PATH_INFO /emailform/server.asp
PATH_TRANSLATED c:\inetpub\wwwroot\emailform\server.asp
QUERY_STRING  
REMOTE_ADDR 192.168.1.100
REMOTE_HOST 192.168.1.100
REMOTE_USER  
REQUEST_METHOD GET
SCRIPT_NAME /emailform/server.asp
SERVER_NAME poseidon
SERVER_PORT 80
SERVER_PORT_SECURE 0
SERVER_PROTOCOL HTTP/1.1
SERVER_SOFTWARE Microsoft-IIS/5.1
URL /emailform/server.asp
HTTP_ACCEPT */*
HTTP_ACCEPT_LANGUAGE en-us
HTTP_CONNECTION Keep-Alive
HTTP_HOST poseidon
HTTP_USER_AGENT Mozilla/4.0 (compatible MSIE 6.0 Windows NT 5.1 SV1 .NET CLR 1.1.4322)
HTTP_ACCEPT_ENCODING gzip, deflate
HTTP_X_REWRITE_URL /emailform/server.asp

Banner
ASP (Active Server Pages) is a technology developed by Microsoft. Pages using ASP are primarily developed in JScript, or VBScript and are integrated into the HTML of your Web pages. The ASP code is compiled on-the-fly by the server and the resulting output is standard HTML. By using ASP, Web pages can be dynamic, full of ever-changing content, and browser independent.
Active Server Pages asp source code database MS SQL MS Access .mdb adovbs.inc cookies calendar codes sql commands scripts asp programming tutorials iis web server components CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspclassifieds.com, www.powerasp.com,www.cjwsoft.com,www.aspphotogallery.com,www.codewanker.com,www.aspprotect.com,www.aspbanner.com,www.abay.com

 

Link to "The Wanker"
© 2007 CodeWanker - Active Server Pages Articles, Code Snippets, & Tutorials