|
|
package com.monitor.other.maliciousip.service.impl;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.math.NumberUtils;
|
...
|
...
|
@@ -16,8 +18,10 @@ import com.alibaba.fastjson.JSON; |
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import com.monitor.other.maliciousip.MaliciousDetailIp;
|
|
|
import com.monitor.other.maliciousip.MaliciousIp;
|
|
|
import com.monitor.other.maliciousip.MaliciousIpLook;
|
|
|
import com.monitor.other.maliciousip.UpLoadError;
|
|
|
import com.monitor.other.maliciousip.service.MaliciousIpService;
|
|
|
import com.monitor.other.maliciousip.util.RedisReadMaliciousUtil;
|
|
|
import com.monitor.other.maliciousip.util.RedisReadUtil;
|
|
|
import com.monitor.other.maliciousip.util.RedisWriteUtil;
|
|
|
|
...
|
...
|
@@ -41,6 +45,9 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
|
@Autowired
|
|
|
private RedisWriteUtil redisWrite;
|
|
|
|
|
|
@Autowired
|
|
|
private RedisReadMaliciousUtil redisReadMalicious;
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
* @see com.monitor.other.maliciousip.service.MaliciousIpService#getIps()
|
|
|
* 从Redis中获取恶意ip集合
|
...
|
...
|
@@ -111,6 +118,32 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
|
return response;
|
|
|
}
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
* @see com.monitor.other.maliciousip.service.MaliciousIpService#lookIps()
|
|
|
* 查看已经上传过的恶意ip
|
|
|
*/
|
|
|
@Override
|
|
|
public BaseResponse<List<MaliciousIpLook>> lookIps() {
|
|
|
BaseResponse<List<MaliciousIpLook>> response = new BaseResponse<>();
|
|
|
List<MaliciousIpLook> looks = new ArrayList<>();
|
|
|
MaliciousIpLook look;
|
|
|
try{
|
|
|
Set<String> values = redisReadMalicious.getIps();
|
|
|
if(CollectionUtils.isNotEmpty(values)){
|
|
|
for (String string : values) {
|
|
|
look = new MaliciousIpLook();
|
|
|
look.setIp(string);
|
|
|
|
|
|
looks.add(look);
|
|
|
}
|
|
|
response.setData(looks);
|
|
|
}
|
|
|
}catch(Exception e){
|
|
|
logger.error(" - MaliciousIpServiceImpl - getDetail - error", e);
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
class ComparatorIp implements Comparator<MaliciousIp> {
|
|
|
public int compare(MaliciousIp e1, MaliciousIp e2) {
|
|
|
int count1 = e1.getCount();
|
...
|
...
|
@@ -138,4 +171,24 @@ public class MaliciousIpServiceImpl implements MaliciousIpService { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 移除恶意ip
|
|
|
* @param ips
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public BaseResponse<UpLoadError> removeIp(String[] ips) {
|
|
|
BaseResponse<UpLoadError> response = new BaseResponse<>();
|
|
|
UpLoadError error = new UpLoadError();
|
|
|
try{
|
|
|
redisWrite.removeIp(ips);
|
|
|
error.setStatus("0");
|
|
|
}catch(Exception e){
|
|
|
error.setStatus("1");
|
|
|
error.setMessage(e.getMessage());
|
|
|
}
|
|
|
response.setData(error);
|
|
|
return response;
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|