0

I am using the bellow code to know client ip but it is giving my server ip, Please someone make necessary changes if any,

Thanks in advance,

protected string GetComputer_InternetIP()
{
    // check IP using DynDNS's service
    WebRequest request = WebRequest.Create("http://checkip.dyndns.org");
    WebResponse response = request.GetResponse();
    StreamReader stream = new StreamReader(response.GetResponseStream());

    // IMPORTANT: set Proxy to null, to drastically INCREASE the speed of request
    //request.Proxy = null;

    // read complete response
    string ipAddress = stream.ReadToEnd();

    // replace everything and keep only IP
    return ipAddress.
        Replace("<html><head><title>Current IP Check</title></head><body>Current IP Address: ", string.Empty).
        Replace("</body></html>", string.Empty);
}
Gurunadh
  • 453
  • 2
  • 10
  • 24
  • Yes, it is because it is the server that is making a request to DynDns so it is the server's IP that is detected. Check out http://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net – Tobiasz Oct 09 '13 at 05:44
  • try this like http://stackoverflow.com/questions/13798286/ip-address-of-the-user-who-is-browsing-my-website – Ravi Oct 09 '13 at 05:46
  • 1
    Why do a webrequest to get it from somewhere else? Try: http://stackoverflow.com/questions/2620932/get-users-ip-address – Tom Heard Oct 09 '13 at 05:47
  • http://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net or try this one... – khalid khan Oct 09 '13 at 06:14
  • stackoverflow.com/questions/735350/, ya i got answer here, thanks, – Gurunadh Oct 09 '13 at 06:51
  • @khalid khan you duplicated my URL. What is interesting is that the upvoted comment is not the one containing the URL you used to solve the case. – Tobiasz Oct 09 '13 at 09:12
  • Hi Tobias, "What is interesting is that the upvoted comment is not the one containing the URL you used to solve the case", i don't understand this, is it for me? and i used the answer what you given to me only, – Gurunadh Oct 10 '13 at 06:48

0 Answers0