Click here to Skip to main content
15,889,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get IP address of Client Computer . I have written the code but it showing the IP of server only and not of Client Computer. plz help.


string strip =Request.ServerVariables["REMOTE_ADDR"];

strip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
strip = System.Environment.MachineName.ToString();
Response.Write(strip );
Posted

This may help

System.Net.Dns.GetHostByName(Environment.MachineName).AddressList[0] + "";
 
Share this answer
 
Hi,

Try with the below code

C#
HttpRequest request = HttpContext.Current.Request;
string ipAddress = request.ServerVariables["HTTP_X_FORWARDED_FOR"];

if (ipAddress == null || ipAddress.ToLower() == "unknown")
      ipAddress = currentRequest.ServerVariables["REMOTE_ADDR"];

return ipAddress;


This may help you.
 
Share this answer
 
Try this

C#
HttpContext.Current.Request.UserHostAddress
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900