feat: 添加slrs业务子项目 修改问题文件
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package com.adc.da.util;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class IpUtil {
|
||||
private IpUtil() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
private static boolean checkIp(String ip) {
|
||||
return ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip);
|
||||
}
|
||||
|
||||
public static String getIpAddr(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
|
||||
if (checkIp(ip)) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
} else if (ip.length() > 15) {
|
||||
String[] ips = ip.split(",");
|
||||
|
||||
for(int index = 0; index < ips.length; ++index) {
|
||||
String strIp = ips[index];
|
||||
if (!"unknown".equalsIgnoreCase(strIp)) {
|
||||
ip = strIp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return StringUtils.trim(ip);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user