欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

根据ip获取地点

程序员文章站 2022-03-31 22:51:47
#region 根据ip获取地点 /// 获取Ip归属地 /// /// ip /// 归属地 public static string GetIpAddress(string ip) { ......

#region 根据ip获取地点
/// 获取Ip归属地
/// </summary>
/// <param name="ip">ip</param>
/// <returns>归属地</returns>
public static string GetIpAddress(string ip)
{
JavaScriptSerializer Jss = new JavaScriptSerializer();
//http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42 调用新浪的接口
string address = string.Empty;
try
{
string reText = WebRequestPostOrGet("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=" + ip, "");
Dictionary<string, object> DicText = (Dictionary<string, object>)Jss.DeserializeObject(reText);
address = DicText["city"].ToString();
//Log.Loger("city:" + address, true);
}
catch { }
return address;
}
#endregion