客户端IP获取

/**
  * 根据HttpServletRequest获取客户端IP地址. 包括对于设置过代理方式等情况
  *
  * @param request
  * @return
  */
 public static String getIp(HttpServletRequest request) {
  String ip = request.getHeader("x-forwarded-for");
  if (null == ip || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
   ip = request.getHeader("Proxy-Client-IP");
  }
  if (null == ip || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
   ip = request.getHeader("WL-Proxy-Client-IP");
  }
  if (null == ip || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
   ip = request.getRemoteAddr();
  }
  if (null != ip) {
   String[] ips = com.paic.pafa.app.lwc.core.util.StringUtils.tokenizeToStringArray(ip, ",; ", true, true);
   ip = ips[0];
  }
  return ip;
 }

posted @ 2015-12-03 17:29  神玄晓  阅读(163)  评论(0编辑  收藏  举报