Server:
//Method 1
Httpcontext. Current. Request. userhostaddress;
//Method 2
Httpcontext. Current. Request. servervariables ["Remote_addr"];
// method 3
string strhostname = system. net. DNS. gethostname ();
string clientipaddress = system. net. DNS. gethostaddresses (strhostname ). getvalue ( 0 ). tostring ();
//Method 4 (ignore proxy)
Httpcontext. Current. Request. servervariables ["Http_x_forwarded_for"];
Client:
//Method 5
VaR IP= '<! -- # Echo Var = "remote_addr" -->';
Alert ("Your IP address is"+IP );
// Method 6 (ignore proxy)
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 provides a server-side solution, which is good:
If (Context. Request. servervariables [ " Http_via " ] ! = Null ) // Using proxy
{
IP = Context. Request. servervariables [ " Http_x_forwarded_for " ]. Tostring (); // Return real client IP.
}
Else // Not using proxy or can't get the client IP
{
IP = Context. Request. servervariables [ " Remote_addr " ]. Tostring (); // While it can't get the client IP, it will return proxy IP.
}
Note:
1Some proxies will not send us real IP addresses.
2Some clients will not send us IP addresses because of the "header_access deny" security settings.