根据ip地址获取城市

 

var ip=context.Request.UserHostAddress;

string url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=" + ip;
WebClient MyWebClient = new WebClient();
MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
Byte[] pageData = MyWebClient.DownloadData(url); //从指定网站下载数据
string stt = Encoding.GetEncoding("GBK").GetString(pageData).Trim();
return stt.Substring(stt.Length - 2, 2);

转载于:https://www.cnblogs.com/1955/p/9019159.html

你可能感兴趣的:(根据ip地址获取城市)