在百度上找啊找,找到淘宝Ip地址库,官方介绍的相当诱人,准确率高,数据质量有保障,提供国家、省、市、县、运营商全方位信息,信息维度广,格式规范,但是限制每秒10次的访问(这个比较无语)。
淘宝IP地址库,提供API http://ip.taobao.com/
接口说明
1. 请求接口(GET):
http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串]
2. 响应信息:
(json格式的)国家 、省(自治区或直辖市)、市(县)、运营商
3. 返回数据格式:
{"code":0,"data":{"ip":"210.75.225.254","country":"\u4e2d\u56fd","area":"\u534e\u5317",
"region":"\u5317\u4eac\u5e02","city":"\u5317\u4eac\u5e02","county":"","isp":"\u7535\u4fe1",
"country_id":"86","area_id":"100000","region_id":"110000","city_id":"110000",
"county_id":"-1","isp_id":"100017"}}
其中code的值的含义为,0:成功,1:失败。
1 :IP转换
准备好工具,后面就好弄啦, IPHelper提供了各种,IP<->byte[]<->Long 转换
2 :多线程疯狂获取IP
3: Http请求的Json结果,并反序列化成对象
http请求这个相当简单。网上一大把,这里主要说一下json序列化,在这里本人建议采用Newtonsoft.Json.dll 下载地址: http://json.codeplex.com/ 性能和兼容性达到最好
Http请求
}
}
Json序列化
private string _ip;
/// <summary>
/// IP地址
/// </summary>
public string ip
{ // http://www.jbxue.com
get { return _ip; }
set { _ip = value; }
}
private string _country;
/// <summary>
/// 国家
/// </summary>
public string country
{
get { return _country; }
set { _country = value; }
}
private string _country_id;
/// <summary>
/// 国家编号
/// </summary>
public string country_id
{
get { return _country_id; }
set { _country_id = value; }
}
private string _area;
/// <summary>
/// 地区
/// </summary>
public string area
{
get { return _area; }
set { _area = value; }
}
private string _area_id;
/// <summary>
/// 地区编号
/// </summary>
public string area_id
{
get { return _area_id; }
set { _area_id = value; }
}
private string _region;
/// <summary>
/// 区域
/// </summary>
public string region
{
get { return _region; }
set { _region = value; }
}
private string _region_id;
/// <summary>
/// 区域编号
/// </summary>
public string region_id
{
get { return _region_id; }
set { _region_id = value; }
}
private string _city;
/// <summary>
///城市
/// </summary>
public string city
{
get { return _city; }
set { _city = value; }
}
private string _city_id;
/// <summary>
/// 城市编号
/// </summary>
public string city_id
{
get { return _city_id; }
set { _city_id = value; }
}
private string _county;
/// <summary>
/// 县
/// </summary>
public string county
{
get { return _county; }
set { _county = value; }
}
private string _county_id;
/// <summary>
/// 县编号
/// </summary>
public string county_id
{
get { return _county_id; }
set { _county_id = value; }
}
private string _isp;
/// <summary>
/// 供应商
/// </summary>
public string isp
{
get { return _isp; }
set { _isp = value; }
}
private string _isp_id;
/// <summary>
/// 供应商ID
/// </summary>
public string isp_id
{
get { return _isp_id; }
set { _isp_id = value; }
}
}
/// <summary>
/// 淘宝api 返回的json数据
/// </summary>
public partial class TaobaoJsonData
{
public int code { get; set; }
public taobaoIPdata data { get; set; }
}
序列号对象taobaoIPdata
4:插入到数据库中。。。剩下的自己随便搞啦