如何通过ip地址知道国家和城市
本文关键字:国家 城市 何通过 ip 地址 | 更新日期: 2023-09-27 18:14:31
我有一个网站,用户可以发送消息给管理员,我想知道用户的国家和城市通过使用他的IP地址?
当我在服务器上发布我的网站时,我的问题开始了,当任何用户发送消息时,我的函数为不同地方的所有用户选择相同的IP地址,并具有不同的IP,这是我的代码:
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);
}
有几个在线服务显示您的IP地址以及与该IP地址或输入网站的任何其他IP地址相关联的城市、州或国家。