1234567891011121314151617181920212223242526272829303132 |
- package com.rf.fileCrack.utils;
- import javax.servlet.http.HttpServletRequest;
- /**
- * @author lpf
- * @description:
- * @date 2021/12/2517:59
- */
- public class IPUtiles {
- public static String getRealIp(HttpServletRequest request) {
- String ip = request.getHeader("X-Real-IP");
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- 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 (ip != null && ip.contains(",")) {
- String[] ipArray = ip.split(",");
- ip = ipArray[0];
- }
- return ip;
- }
- }
|