클라이언트 IP 추출 메서드 추가

main
이범준 12 months ago
parent 16d80b3c7d
commit e420217d11

@ -118,6 +118,14 @@
<artifactId>icu4j</artifactId>
<version>75.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

@ -3,8 +3,40 @@ package cokr.xit.applib;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
public class AppCmmnUtil {
/**
* http 릿 IP .
* @param http 릿
* @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;
}
/**
* (,) .
* @param

Loading…
Cancel
Save