Browse Source

调整获取ip地址方法

dev_shibei_match
jianjun 5 years ago
parent
commit
409a9526b9
  1. 7
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IpUtils.java

7
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IpUtils.java

@ -49,6 +49,12 @@ public class IpUtils {
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
//对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if (ip != null && ip.length() > 15) { //"***.***.***.***".length() = 15
if (ip.indexOf(",") > 0) {
ip = ip.substring(0, ip.indexOf(","));
}
}
} catch (Exception e) {
logger.error("IpUtils ERROR ", e);
}
@ -58,6 +64,7 @@ public class IpUtils {
/**
* desc:获取本地Ip
*
* @return
*/
public static String getServerIp() {

Loading…
Cancel
Save