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);
}