Oasis' story

자바에서 접속자 IP 가져오기 본문

Program Note/JAVA

자바에서 접속자 IP 가져오기

oasispapa 2017. 10. 10. 10:58


 /**
  * 사용자 접속IP 확인
  *
  * @param request
  * @return
  */
 private String getClientIP(HttpServletRequest request) {
        String clientIp = request.getHeader("Proxy-Client-IP");
        if (clientIp == null) {

            clientIp = request.getHeader("WL-Proxy-Client-IP");
            if (clientIp == null) {
                clientIp = request.getHeader("X-Forwarded-For");
                if (clientIp == null) {
                    clientIp = request.getRemoteAddr();
                }
            }
        }
        return clientIp;
    }