段飞宇
2 years ago
204 changed files with 1664 additions and 533 deletions
@ -0,0 +1,49 @@
|
||||
package com.hnac.hzims.common.utils; |
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
/** |
||||
* @Author WL |
||||
* @Version v1.0 |
||||
* @Serial 1.0 |
||||
* @Date 2023/3/29 11:45 |
||||
*/ |
||||
public class IPUtils { |
||||
|
||||
/** |
||||
* 获取客户端ip地址 |
||||
* @param request |
||||
* @return |
||||
*/ |
||||
public static String getIpAddress(HttpServletRequest request) { |
||||
|
||||
String sourceIp = null; |
||||
|
||||
String ipAddresses = request.getHeader("x-forwarded-for"); |
||||
|
||||
if (ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { |
||||
ipAddresses = request.getHeader("Proxy-Client-IP"); |
||||
} |
||||
if (ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { |
||||
ipAddresses = request.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
if (ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { |
||||
ipAddresses = request.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
if (ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { |
||||
ipAddresses = request.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
if (ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { |
||||
ipAddresses = request.getRemoteAddr(); |
||||
} |
||||
if (StringUtils.isEmpty(ipAddresses)) { |
||||
sourceIp = ipAddresses.split(",")[0]; |
||||
} |
||||
|
||||
return sourceIp; |
||||
} |
||||
|
||||
|
||||
} |
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue