根据IP获取国家
2014-12-12 10:46
260 查看
国外的还算比较权威的IP地址库,而且免费,每天调用次数不超过1000免费。超过另收费。
public string Ip2Country(string ip) { try { string url = "http://api.ipinfodb.com/v3/ip-country/?key=<your key,should regist first>&ip=" + ip; string rst = HttpCrossDomain.Get(url,10000); if (rst.Split(';').Count() >= 4) rst = rst.Split(';')[3]; else rst = ""; return rst; } catch { return "ERROR"; } }
/// <summary> /// 跨域访问 /// </summary> /// <param name="url"></param> /// <param name="param"></param> /// <returns></returns> public static string Get(string url, int time = 60000) { Uri address = new Uri(url); HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest; request.Method = "GET"; request.ContentType = "application/json;charset=utf-8"; //"application/x-www-form-urlencoded"; request.Timeout = time; string result = ""; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); result = reader.ReadToEnd(); } return (result); }
相关文章推荐
- android 根据网络来获取外网ip地址及国家,地区的接口
- Laravel根据Ip获取国家,城市信息
- Go实战--golang中获取公网ip、查看内网ip、检测ip类型、校验ip区间、ip地址string和int转换、根据ip判断地区国家运营商等
- android 根据网络来获取外网ip地址及国家,地区的接口
- 根据IP获取国家省市
- 根据IP获取所在的国家城市
- Laravel根据Ip获取国家,城市信息
- Java根据IP获取国家省级地市信息
- 根据IP获取地区
- 根据用户IP获取用户的地址。
- 根据游戏类型ID获取游戏服务器IP及硬件码的SQL
- 根据IP获取用户信息,sina js和纯真IP两种方式
- 根据主机名获取IP
- 如何用PB根据hostname获取IP
- 根据使用者的IP获取当前所在省市
- 获取指定(访客)IP的所有信息,地址、邮政编码、国家、经纬度等的API
- html 根据ip获取当地天气预报
- C# 根据局域网IP获取主机名称
- javaScript根据IP来获取城市等相关信息
- 根据ip获取当地天气预告的实现asp.net实例