
3 changed files with 32 additions and 2 deletions
@ -0,0 +1,29 @@ |
|||||||
|
package com.hnac.hzims.common.logs.utils; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author WL |
||||||
|
* @Version v1.0 |
||||||
|
* @Serial 1.0 |
||||||
|
* @Date 2023/7/26 11:34 |
||||||
|
*/ |
||||||
|
public class WebIpUtils { |
||||||
|
|
||||||
|
public static String getIpAddr(HttpServletRequest request) { |
||||||
|
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.getRemoteAddr(); |
||||||
|
} |
||||||
|
if (!(null == ip || "".equals(ip.trim()) || "null".equalsIgnoreCase(ip.trim())) && ip.contains(",")) { |
||||||
|
ip = ip.split(",")[0]; |
||||||
|
} |
||||||
|
return ip; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue