互联网有很多接口可以实现通过ip查询到具体的位置,如下:
通过淘宝IP地址库获取IP位置
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:失败。
新浪的接口 :http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=218.192.3.42
返回值
var remote_ip_info = {"ret":1,"start":"218.192.0.0","end":"218.192.7.255","country":"\u4e2d\u56fd","province":"\u5e7f\u4e1c","city":"\u5e7f\u5dde","district":"","isp":"\u6559\u80b2\u7f51","type":"\u5b66\u6821","desc":"\u5e7f\u5dde\u5927\u5b66\u7eba\u7ec7\u670d\u88c5\u5b66\u9662"};
通过jqry 获取相应的数据
$.getScript('数据接口',function(){
//新浪:remote_ip_info.country
})
腾讯IP分享计划的地址获取IP所在地:
http://ip.qq.com/cgi-bin/searchip?searchip1=ip
但是好像查询的结果都不算是特别准确,下面记录一个很准确的项目
项目地址:https://github.com/wzhe06/ipdatabase
二叉树快速搜索IP地址数据库
数据源采用2015年广告协会制定的IP地址标准数据库,中国互联网广告行业统一采用的标准IP库。
此项目使用poi方式读取excel表格,按照图中所示,我们应该读取第一列和第二列
默认的方法是只查询出省份,但是一般我们要的是省份+城市.所有要修改下代码
row.getCell(0)的意思就是获取第一列,所以我们要改成
String adress = row.getCell(0).getStringCellValue()+row.getCell(1).getStringCellValue();
这样就能获取到身份+城市的信息了
补充一下poi的相关操作
public static void showExcel() throws Exception {
HSSFWorkbook workbook=new HSSFWorkbook(new FileInputStream(new File("/file/student.xls")));
HSSFSheet sheet=null;
for (int i = 0; i < workbook.getNumberOfSheets(); i++) {//获取每个Sheet表
sheet=workbook.getSheetAt(i);
for (int j = 0; j < sheet.getPhysicalNumberOfRows(); j++) {//获取每行
HSSFRow row=sheet.getRow(j);
for (int k = 0; k < row.getPhysicalNumberOfCells(); k++) {//获取每个单元格
System.out.print(row.getCell(k)+"\t");
}
System.out.println("---Sheet表"+i+"处理完毕---");
}
}