ip 추려서 true/false return 


private boolean isAccessable(HttpServletRequest request){


boolean condition = false;

String userIp = request.getRemoteAddr();

log.debug(">>>>>>>>>>>>>>>>>>>>>>>userIp:" + userIp);

String accessIp = null;

ResourceBundle property = null;

try{

property  = ResourceBundle.getBundle("egovframework.egovProps.conf.accessIp");

accessIp = property.getString("IP");

log.debug(">>>>>>>>>>>>>>>>>>>>>>>accessIp:" + accessIp);

String[] accessIpes = accessIp.split(",");

for(String ip : accessIpes){

if(ip.indexOf("*") > -1){

log.debug(">>>>>>>>>>>>>>>>>>>>>>>ip.indexOf(\"*\"):" + ip);

if( userIp.indexOf(ip.substring(0, ip.indexOf("*"))) > -1 ){

condition = true;

break;

}

}else if(ip.indexOf("~") > -1){

log.debug(">>>>>>>>>>>>>>>>>>>>>>>ip.indexOf(\"~\"):" + ip);

String[] ipes = ip.split("~");

String _ip1 = ipes[0].substring(0, ipes[0].lastIndexOf(".")+1);

log.debug(">>>>>>>>>>>>>>>>>>>>>>>_ip1:" + _ip1);

String _ip2 = ipes[1].substring(0, ipes[1].lastIndexOf(".")+1);

log.debug(">>>>>>>>>>>>>>>>>>>>>>>_ip2:" + _ip2);

String _userIp = userIp.substring(0, userIp.lastIndexOf(".")+1);

log.debug(">>>>>>>>>>>>>>>>>>>>>>>_userIp:" + _userIp);


if(userIp.indexOf(_ip1) > -1 && userIp.indexOf(_ip2) > -1){

String _ip11 = ipes[0].substring(ipes[0].lastIndexOf(".")+1);

String _ip22 = ipes[1].substring(ipes[1].lastIndexOf(".")+1);

String _userIp2 = userIp.substring(userIp.lastIndexOf(".")+1);

if( ( Integer.parseInt(_userIp2) >= Integer.parseInt(_ip11) ) && ( Integer.parseInt(_userIp2) <= Integer.parseInt(_ip22) ) ){

condition = true;

break;

}

}

}else{

log.debug(">>>>>>>>>>>>>>>>>>>>>>>ip:" + ip);

if(userIp.equals(ip)){

condition = true;

break;

}

}

}

}catch(Exception ignored){

condition = false;

}


return condition;

}




'JAVA' 카테고리의 다른 글

[JAVA] jndi2  (0) 2017.11.28
[JAVA] javaee 오류  (0) 2017.11.27
[JAVA] IE11 첨부파일 한글깨짐  (0) 2017.11.27
[JAVA]https 로 변경  (0) 2017.11.27
[JAVA]html를 이미지로 변환  (2) 2017.11.24
블로그 이미지

마크제이콥스

초보 개발자의 이슈및 공부 내용 정리 블로그 입니다.

,