/**
*
*
*
Copyright 1994 JsonInternational
*
All rights reserved.
*
Created on 19941115
*
Created by Jason
*
*
*/
package cn.ucaner.alpaca.framework.utils.ip;
import javax.servlet.http.HttpServletRequest;
/**
* @Package:cn.ucaner.framework.utils
* @ClassName:IPAddress
* @Description:
ip地址
* @Author: - Jason
* @CreatTime:2017年8月30日 下午2:12:19
* @Modify By:
* @ModifyTime:
* @Modify marker:
* @version V1.0
*/
public class IPAddress {
/**
* 获取客户端ip地址
* @param request
* @return
*/
public static String getClientIpAddress(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Cdn-Src-Ip");
}
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.indexOf(",") > -1) {
ip = ip.substring(0, ip.indexOf(","));
}
return ip;
}
}