1. 首先定义一张表用来记录用户的IP访问

------------------------------------ --用户绑定的IP ------------------------------------ DECLARE VC_STR VARCHAR2(2000); VN_COUNT NUMBER; BEGIN --查看是否存在NRE_BUSINESSTYPE SELECT COUNT(*) INTO VN_COUNT FROM USER_TABLES WHERE TABLE_NAME = 'CHAT_USER_BIND'; --如果没有则新增加表 IF VN_COUNT < 1 THEN VC_STR :=' CREATE TABLE CHAT_USER_BIND ( ID VARCHAR2(32) DEFAULT SYS_GUID() PRIMARY KEY, USER_CODE VARCHAR2(32), USER_IP VARCHAR2(50), USER_TYPE VARCHAR2(2), CREATE_DATE DATE DEFAULT SYSDATE, )'; EXECUTE IMMEDIATE VC_STR; commit; END IF; END; / comment on column CHAT_USER_BIND.ID is '主键'; comment on column CHAT_USER_BIND.USER_CODE is '用户代码'; comment on column CHAT_USER_BIND.USER_IP is '绑定服务端IP'; comment on column CHAT_USER_BIND.CREATE_DATE is '创建时间'; comment on column CHAT_USER_BIND.USER_TYPE is '0注册成功,1登录成功,2绑定成功'; /

2.统计IP的访问数量,单个用户重复IP去重

查看网络ip分布(访问IP分布地区统计图)(1)

3.通过工具ip2region获取ip的地址信息

1.获取IP119.118.179.94=>地址中国|0|辽宁省|沈阳市|联通 2.获取的IP信息主要用到的是第二个坐标的省份,这里把省份去掉(因为echarts的map信息没有用省结尾) @ResponseBody @RequestMapping(value="/ipMap") public List<Map<String,String>> getIPMap(){ List<Map<String,Object>> ipMap=this.userService.getIPCount(); Map<String,String> mapCount=new HashMap<String,String>(); if(null!=ipMap && ipMap.size()>0) { for(Map<String,Object> map : ipMap) { String address=IPUtil.getAddress(map.get("IP").toString(),IPDBTargetPath); logger.info("获取IP{}=>地址{}",map.get("IP"),address); if(!StringUtil.isNUll(address)) { String provice=address.split("\\|")[2]; if(provice.endsWith("省")) { provice=provice.substring(0,provice.length()-1); if(StringUtil.isNUll(mapCount.get(provice))) { mapCount.put(provice, map.get("COUNT_IP").toString()); }else { mapCount.put(provice, Integer.valueOf(mapCount.get(provice)) Integer.valueOf(map.get("COUNT_IP").toString()) ""); } } } } } List<Map<String,String>> listMapCount=new ArrayList<Map<String,String>>(); for(String key : mapCount.keySet()) { Map<String,String> map=new HashMap<String,String>(); map.put("name", key); map.put("value", mapCount.get(key)); listMapCount.add(map); } return listMapCount; }

4.借助echarts展示

这里主要参考了(https://github.com/Jackyyans/code123/tree/master/normal)

5.效果图

查看网络ip分布(访问IP分布地区统计图)(2)

,