package com.viathink.utils;
import javax.servlet.http.HttpServletRequest;
/**
* Ip地址工具类
* @author LiuJunGuang
* @date 2014年2月22日下午3:02:41
*/
public class IpUtils {
/**
* 获取客户端IP地址
* @author LiuJunGuang
* @param request
* @return
* @date 2014年2月22日下午3:03:05
*/
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.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
}
阅读(2285) | 评论(0) | 转发(0) |