장쫄깃 기술블로그

[Java] IP 주소 검색 본문

Programming Language/Java

[Java] IP 주소 검색

장쫄깃 2022. 4. 14. 16:39
728x90


public String getClientIP(HttpServletRequest request) {
	String ip = request.getHeader("X-Forwarded-For");
	
	if (ip == null) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null) {
			ip = request.getHeader("HTTP_CLIENT_IP");
		}
		if (ip == null) {
			ip = request.getHeader("HTTP_X_FORWARDED_FOR");
		}
		if (ip == null) {
			ip = request.getRemoteAddr();
		}
	
	return ip;
}
728x90