Service side:
1 //Method One2 HttpContext.Current.Request.UserHostAddress;3 4 //Method Two5httpcontext.current.request.servervariables["REMOTE_ADDR"];6 7 //Method Three8 stringStrhostname =System.Net.Dns.GetHostName ();9 stringclientipaddress = System.Net.Dns.GetHostAddresses (strhostname). GetValue (0). ToString ();Ten One //method Four (ignoring proxies) Ahttpcontext.current.request.servervariables["http_x_forwarded_for"];
Client:
1 //Method Five2 varIP ='<!--#echo var= "REMOTE_ADDR" -';3Alert"Your IP Address is"+IP);4 5 6 7 //method Six (ignoring proxies)8 function getlocalipaddress ()9 { Ten varobj =NULL; One varRSLT =""; A Try - { -obj =NewActiveXObject ("Rcbdyctl. Setting"); theRSLT =obj. getipaddress; -obj =NULL; - } - Catch(e) + { - // + } A returnrslt; at}
An MCT Maulik Patel from India provides a service-side solution:
1 if(context.request.servervariables["Http_via"]!=NULL)//using proxy2 { 3ip=context.request.servervariables["http_x_forwarded_for"]. ToString ();//Return Real client IP.4 }5 Else//Not using proxy or can ' t get the Client IP6 { 7ip=context.request.servervariables["REMOTE_ADDR"]. ToString ();//while it can ' t get the Client IP, it'll return proxy IP.9}
Note:
- Some proxies are not sent to our real IP address.
- Some clients will not send us IP because of "header_access deny" security settings.