Dev Language/JAVA

JAVA Client IP 얻기

타카스 류지 2019. 9. 17. 09:28

String ip = request.getHeader("X-Forwarded-For");

 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 

     ip = request.getHeader("Proxy-Client-IP"); 

 } 

 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 

     ip = request.getHeader("WL-Proxy-Client-IP"); 

 } 

 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 

     ip = request.getHeader("HTTP_CLIENT_IP"); 

 } 

 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 

     ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 

 } 

 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 

     ip = request.getRemoteAddr(); 

 }

 

 

출처 : https://www.lesstif.com/pages/viewpage.action?pageId=20775886