General procedures have access to the user's IP address command, but we visit the site there are two kinds of our common users, one is the use of proxy IP Internet users, I would like to introduce the following.
Get User IP address in ASP our easiest way to get here is to use the
The code is as follows |
|
Request.ServerVariables ("REMOTE_ADDR") |
However, if the user uses the proxy server IP address is not correct, but we can pass
The code is as follows |
|
Request.ServerVariables ("REMOTE_ADDR") |
Results The above two methods of obtaining IP can be operated as follows
The code is as follows |
|
Userip = Request.ServerVariables ("Http_x_forwarded_for") If Userip = "" Then Userip = Request.ServerVariables ("REMOTE_ADDR") |
The above is just a simple method of judging, in the actual application we may encounter more cases, the following look a good example
code is as follows |
&nbs P; |
<%private Function GetIP () Dim stripaddr If Request.ServerVariables ("http_x_forwarded_for") = "" OR InStr (Request.ServerVariables ("Http_x_forwarded_for"), " Unknown ") > 0 then stripaddr = Request.ServerVariables (" remote_addr ") ElseIf InStr ( Request.ServerVariables ("Http_x_forwarded_for"), ",") > 0 then stripaddr = Mid (Request.ServerVariables (" Http_x_forwarded_for "), 1, InStr (Request.ServerVariables (" Http_x_forwarded_for "),", ")-1) ElseIf InStr ( Request.ServerVariables ("Http_x_forwarded_for"), ";" > 0 then stripaddr = Mid (Request.ServerVariables ("Http_x_forwarded_for"), 1, INSTR ( Request.ServerVariables ("Http_x_forwarded_for"), ";" -1) else stripaddr = Request.ServerVariables ("http_x_forwarded_for") End if GetIP = Trim (Mid (stripaddr, 1) End function Ip=getip () Response. Write (IP) %> |
This can almost get the user's real IP address, but also can not save all the agents are able to obtain, but we all use the above method.
If you have friends who use ASP.net, refer to the following methods to obtain
code is as follows |
&nbs P; |
//method one HttpContext.Current.Request.UserHostAddress; //Method two httpcontext.current.request.servervariables["REMOTE_ADDR"]; //Method Three String strhostname = System.Net.Dns.GetHostName (); String clientipaddress = System.Net.Dns.GetHostAddresses (Strhostname). GetValue (0). ToString (); //Method IV (ignoring proxy) httpcontext.current.request.servervariables["Http_x_forwarded_for"]; //Method five var ip = ' <!--#echo var= ' remote_addr '--> '; Alert ("Your IP address is" +IP); //Method VI (ignoring proxy) function getlocalipaddress () { var obj = null; var rslt = ""; try { obj = new ActiveXObject ("Rcbdyctl. Setting "); &nbsP rslt = obj. getipaddress; obj = null; } catch (E) { //&NBSP } return rslt; &NBSP } |