|
|
package com.monitor.other.maliciousip.util;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import redis.clients.jedis.Jedis;
|
|
|
import redis.clients.jedis.JedisPool;
|
|
|
import redis.clients.jedis.JedisPoolConfig;
|
...
|
...
|
@@ -10,11 +13,20 @@ import redis.clients.jedis.JedisPoolConfig; |
|
|
*
|
|
|
*/
|
|
|
public class RedisWriteUtil {
|
|
|
/**
|
|
|
* 日志接口
|
|
|
*/
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
/**
|
|
|
* Redis set 集合,里面放的都是ip
|
|
|
*/
|
|
|
private static final String MALICIOUS_IP = "yh:malicious:ips";
|
|
|
private static final String MALICIOUS_IP_HASH = "yh:malicious:ips";
|
|
|
|
|
|
/**
|
|
|
* Redis String 类型
|
|
|
*/
|
|
|
private static final String MALICIOUS_IP = "yh:mip:";
|
|
|
|
|
|
/**
|
|
|
* 黑名单失效时间24小时
|
...
|
...
|
@@ -101,44 +113,69 @@ public class RedisWriteUtil { |
|
|
* @return
|
|
|
*/
|
|
|
public void setIps(String []ips) {
|
|
|
Jedis jedis_qq1 = getJedis_qq1();
|
|
|
Jedis jedis_qq2 = getJedis_qq2();
|
|
|
Jedis jedis_aws1 = getJedis_aws1();
|
|
|
Jedis jedis_aws2 = getJedis_aws2();
|
|
|
|
|
|
jedis_qq1.sadd(MALICIOUS_IP, ips);
|
|
|
jedis_qq1.expire(MALICIOUS_IP, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_qq2.sadd(MALICIOUS_IP, ips);
|
|
|
jedis_qq2.expire(MALICIOUS_IP, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_aws1.sadd(MALICIOUS_IP, ips);
|
|
|
jedis_aws1.expire(MALICIOUS_IP, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_aws2.sadd(MALICIOUS_IP, ips);
|
|
|
jedis_aws2.expire(MALICIOUS_IP, MALICIOUS_IP_EXPIRE);
|
|
|
|
|
|
returnResource(jedis_qq1);
|
|
|
returnResource(jedis_qq2);
|
|
|
returnResource(jedis_aws1);
|
|
|
returnResource(jedis_aws2);
|
|
|
try{
|
|
|
if((null == ips) || (0 == ips.length)){
|
|
|
return;
|
|
|
}
|
|
|
Jedis jedis_qq1 = getJedis_qq1();
|
|
|
Jedis jedis_qq2 = getJedis_qq2();
|
|
|
Jedis jedis_aws1 = getJedis_aws1();
|
|
|
Jedis jedis_aws2 = getJedis_aws2();
|
|
|
|
|
|
//此处用于查询
|
|
|
/*jedis_aws1.sadd(MALICIOUS_IP_HASH, ips);
|
|
|
jedis_aws1.expire(MALICIOUS_IP_HASH, MALICIOUS_IP_EXPIRE);*/
|
|
|
|
|
|
//此处用于拦截
|
|
|
for (String ip : ips) {
|
|
|
jedis_qq1.set(MALICIOUS_IP + ip, "0");
|
|
|
jedis_qq1.expire(MALICIOUS_IP + ip, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_qq2.set(MALICIOUS_IP + ip, "0");
|
|
|
jedis_qq2.expire(MALICIOUS_IP + ip, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_aws1.set(MALICIOUS_IP + ip, "0");
|
|
|
jedis_aws1.expire(MALICIOUS_IP + ip, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_aws2.set(MALICIOUS_IP + ip, "0");
|
|
|
jedis_aws2.expire(MALICIOUS_IP + ip, MALICIOUS_IP_EXPIRE);
|
|
|
}
|
|
|
|
|
|
returnResource(jedis_qq1);
|
|
|
returnResource(jedis_qq2);
|
|
|
returnResource(jedis_aws1);
|
|
|
returnResource(jedis_aws2);
|
|
|
}catch(Exception e){
|
|
|
logger.error(" - RedisWriteUtil - setIps - error", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void removeIp(String[] ips){
|
|
|
Jedis jedis_qq1 = getJedis_qq1();
|
|
|
Jedis jedis_qq2 = getJedis_qq2();
|
|
|
Jedis jedis_aws1 = getJedis_aws1();
|
|
|
Jedis jedis_aws2 = getJedis_aws2();
|
|
|
|
|
|
jedis_qq1.srem(MALICIOUS_IP, ips);
|
|
|
jedis_qq1.expire(MALICIOUS_IP, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_qq2.srem(MALICIOUS_IP, ips);
|
|
|
jedis_qq2.expire(MALICIOUS_IP, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_aws1.srem(MALICIOUS_IP, ips);
|
|
|
jedis_aws1.expire(MALICIOUS_IP, MALICIOUS_IP_EXPIRE);
|
|
|
jedis_aws2.srem(MALICIOUS_IP, ips);
|
|
|
jedis_aws2.expire(MALICIOUS_IP, MALICIOUS_IP_EXPIRE);
|
|
|
|
|
|
returnResource(jedis_qq1);
|
|
|
returnResource(jedis_qq2);
|
|
|
returnResource(jedis_aws1);
|
|
|
returnResource(jedis_aws2);
|
|
|
try{
|
|
|
if((null == ips) || (0 == ips.length)){
|
|
|
return;
|
|
|
}
|
|
|
Jedis jedis_qq1 = getJedis_qq1();
|
|
|
Jedis jedis_qq2 = getJedis_qq2();
|
|
|
Jedis jedis_aws1 = getJedis_aws1();
|
|
|
Jedis jedis_aws2 = getJedis_aws2();
|
|
|
|
|
|
//此处用于查询
|
|
|
/*jedis_aws1.srem(MALICIOUS_IP_HASH, ips);
|
|
|
jedis_aws1.expire(MALICIOUS_IP_HASH, MALICIOUS_IP_EXPIRE);*/
|
|
|
|
|
|
for (int index = 0; index < ips.length; index ++){
|
|
|
ips[index] = MALICIOUS_IP + ips[index];
|
|
|
}
|
|
|
//此处用于拦截
|
|
|
jedis_qq1.del(ips);
|
|
|
jedis_qq2.del(ips);
|
|
|
jedis_aws1.del(ips);
|
|
|
jedis_aws2.del(ips);
|
|
|
|
|
|
returnResource(jedis_qq1);
|
|
|
returnResource(jedis_qq2);
|
|
|
returnResource(jedis_aws1);
|
|
|
returnResource(jedis_aws2);
|
|
|
}catch(Exception e){
|
|
|
logger.error(" - RedisWriteUtil - setIps - error", e);
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|