서버에 들어오는 사용자의 IP를 조회하는 함수이다.
public static String getIp(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
//log.debug("X-FORWARDED-FOR : " + ip);
if (ip == null) {
ip = request.getHeader("Proxy-Client-IP");
//log.debug("Proxy-Client-IP : " + ip);
}
if (ip == null) {
ip = request.getHeader("WL-Proxy-Client-IP");
//log.debug("WL-Proxy-Client-IP : " + ip);
}
if (ip == null) {
ip = request.getHeader("HTTP_CLIENT_IP");
//log.debug("HTTP_CLIENT_IP : " + ip);
}
if (ip == null) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
//log.debug("HTTP_X_FORWARDED_FOR : " + ip);
}
if (ip == null) {
ip = request.getRemoteAddr();
//log.debug("getRemoteAddr : "+ip);
}
log.debug("Result : IP Address : "+ip);
return ip;
}
서버의 IP를 조회하는 함수
용도 : 로컬, 개발, 운영 환경 분기
public static String getIp(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
//log.debug("X-FORWARDED-FOR : " + ip);
if (ip == null) {
ip = request.getHeader("Proxy-Client-IP");
//log.debug("Proxy-Client-IP : " + ip);
}
if (ip == null) {
ip = request.getHeader("WL-Proxy-Client-IP");
//log.debug("WL-Proxy-Client-IP : " + ip);
}
if (ip == null) {
ip = request.getHeader("HTTP_CLIENT_IP");
//log.debug("HTTP_CLIENT_IP : " + ip);
}
if (ip == null) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
//log.debug("HTTP_X_FORWARDED_FOR : " + ip);
}
if (ip == null) {
ip = request.getRemoteAddr();
//log.debug("getRemoteAddr : "+ip);
}
log.debug("Result : IP Address : "+ip);
return ip;
}