diff --git a/src/main/java/cokr/xit/fims/base/web/MainController.java b/src/main/java/cokr/xit/fims/base/web/MainController.java index f392f329..bb204ec0 100644 --- a/src/main/java/cokr/xit/fims/base/web/MainController.java +++ b/src/main/java/cokr/xit/fims/base/web/MainController.java @@ -21,6 +21,7 @@ import cokr.xit.base.user.service.SigunguDepartmentService; import cokr.xit.base.user.service.UserService; import cokr.xit.fims.base.FimsUser; import cokr.xit.fims.base.service.bean.OgdpBean; +import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.task.TaskRequestMappingHandlerMapping; import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.web.RequestHandlerReader; @@ -163,7 +164,9 @@ public class MainController extends cokr.xit.base.web.MainController { @RequestMapping(name="접속자 IP 확인", value="/ipInfo.do") public ModelAndView ipInfo(HttpServletRequest hreq) { - String remoteAddr = hreq.getRemoteAddr(); + + String remoteAddr = CmmnUtil.getClientIpAddr(hreq); + String net = ""; String LOCAL = "127.0.0.1"; String[] PRIVATES = {"10.","172.16.","172.31.","192.168."}; diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index 3f913fcf..1bd0edca 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -27,6 +27,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletRequest; import org.apache.commons.io.FilenameUtils; import org.springframework.core.io.ClassPathResource; @@ -606,4 +607,33 @@ public class CmmnUtil { return mm * 2.83465f; } + /** + * 클라이언트 IP를 반환한다. + * @param request 서블릿 요청 + * @return 클라이언트 IP + */ + public static String getClientIpAddr(HttpServletRequest request) { + String REGEXP_IPV4_ADDR = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"; + String[] headerNames = {"X-Forwarded-For","Proxy-Client-IP","WL-Proxy-Client-IP","HTTP_CLIENT_IP","HTTP_X_FORWARDED_FOR"}; + + String ip = ""; + for(String headerName : headerNames) { + ip = request.getHeader(headerName); + if(ip != null && ip.contains(",")) { + ip = ip.split(",",-1)[0]; + } + if(ip != null && Pattern.matches(REGEXP_IPV4_ADDR, ip)) { + break; + } + } + + if(ip != null && ip.contains(",")) { + ip = ip.split(",",-1)[0]; + } + if(ip == null || !Pattern.matches(REGEXP_IPV4_ADDR, ip)) { + ip = request.getRemoteAddr(); + } + + return ip; + } } \ No newline at end of file