|
|
|
@ -9,16 +9,21 @@ import java.net.UnknownHostException; |
|
|
|
|
*/ |
|
|
|
|
public class IPUtil { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 未知ip |
|
|
|
|
*/ |
|
|
|
|
public static final String IP_UNKNOWM = "unknown"; |
|
|
|
|
|
|
|
|
|
public static String getIP(HttpServletRequest request){ |
|
|
|
|
|
|
|
|
|
String ip = request.getHeader("x-forwarded-for"); |
|
|
|
|
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ |
|
|
|
|
if(ip == null || ip.length() == 0 || IP_UNKNOWM.equalsIgnoreCase(ip)){ |
|
|
|
|
ip = request.getHeader("Proxy-Client-IP"); |
|
|
|
|
} |
|
|
|
|
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ |
|
|
|
|
if(ip == null || ip.length() == 0 || IP_UNKNOWM.equalsIgnoreCase(ip)){ |
|
|
|
|
ip = request.getHeader("WL-Proxy-Client-IP"); |
|
|
|
|
} |
|
|
|
|
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ |
|
|
|
|
if(ip == null || ip.length() == 0 || IP_UNKNOWM.equalsIgnoreCase(ip)){ |
|
|
|
|
ip = request.getRemoteAddr(); |
|
|
|
|
} |
|
|
|
|
return "0:0:0:0:0:0:0:1".equals(ip) ?"127.0.0.1":ip; |
|
|
|
|