Use Request.ServerVariables ("REMOTE_ADDR") in the ASP to obtain the IP address of the client, but if the client is using a proxy server for access, then the IP address of the proxy server is taken, not the true client IP address.
To obtain a client's real IP address through a proxy server, use Request.ServerVariables ("Http_x_forwarded_for") to read it.
However, it should be noted that not every proxy server can use Request.ServerVariables ("Http_x_forwarded_for") to read the real IP client, and some use this method to read the IP is still the proxy server.
It is also important to note that if the client is not accessed through a proxy server, the value taken with Request.ServerVariables ("Http_x_forwarded_for") will be empty. Therefore, if you want to use this method in your program, you can handle this:
......
Userip = Request.ServerVariables ("Http_x_forwarded_for")
If Userip = "" Then Userip = Request.ServerVariables ("REMOTE_ADDR")
......
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 the agent)
httpcontext.current.request.servervariables["Http_x_forwarded_for"];
Client:
Method Five
var ip = ' <!--#echo var= ' remote_addr '--> ';
Alert ("Your IP address is" +IP);
Method VI (ignoring the agent)
function getlocalipaddress ()
{
var obj = null;
var rslt = "";
Try
{
obj = new ActiveXObject ("Rcbdyctl. Setting ");
Rslt = obj. getipaddress;
obj = null;
}
catch (E)
{
//
}
return rslt;
}
MCT Maulik Patel from India offers a service-side solution that is good:
if (context.request.servervariables["Http_via"]!=null)/server, using proxy
{
Get the Real client address
ip=context.request.servervariables["Http_x_forwarded_for"]. ToString (); return real client IP.
}
else//If you do not use a proxy server or do not have IP not using proxy or can ' t getting the client IP
{
Get the address of the service side
ip=context.request.servervariables["REMOTE_ADDR"]. ToString (); While it can ' t get the Client IP, it'll return proxy IP.
}
Some clients will not send us IP because of "header_access deny" security settings
From:http://hi.baidu.com/snake1964/blog/item/055b78cb7bb0f513bf09e6f0.html
Personal application:
{
string result = String.Empty;
result = httpcontext.current.request.servervariables["http_x_forwarded_for"];
if (string. IsNullOrEmpty (Result))
{
result = httpcontext.current.request.servervariables["REMOTE_ADDR"];
}
if (string. IsNullOrEmpty (Result))
{
result = HttpContext.Current.Request.UserHostAddress;
}
if (string. IsNullOrEmpty (Result) | | ! IsIP (Result))
{
return "127.0.0.1";
}
return result;
}