0

I have a website, user can send messages to admin and I want to know the user country and city by using his IP address ?

My problem starts when I publish my website on server, when any user sends message my function pick the same IP address for the all users in different places and have different IPs and this my code:

   public string getPublicIP()        
   {
        string direction;

        WebRequest request =WebRequest.Create("http://checkip.dyndns.org/");

        WebResponse response = request.GetResponse();

    StreamReader stream = new StreamReader(response.GetResponseStream());

        direction = stream.ReadToEnd();

        stream.Close();

        response.Close(); 

        int first = direction.IndexOf("Address: ") + 9;

        int last = direction.LastIndexOf("");

        direction = direction.Substring(first, last - first);

        return direction.

        Replace("<html><head><title>Current IP Check</title></head>

        <body>Current IP Address: ", string.Empty).

        Replace("</body></html>", string.Empty);

    }
Sunil Kumar
  • 3,142
  • 1
  • 19
  • 33
asmaa ali
  • 23
  • 5

1 Answers1

0

There are several online services that display your IP address and the city, state, or country associated with that IP address or any other IP address entered into the site.

Ghost Developer
  • 1,283
  • 1
  • 10
  • 18