content: package com.amayadream.webchat.utils;
  
  import javax.servlet.http.HttpServletRequest;
  
  /**
   * NAME   :  LeaveSystem/com.amayadream.leave.util
   * Author :  Amayadream
   * Date   :  2015.12.29 16:22
   * TODO   :  网络工具类
   */
  public class NetUtil {
  
      /**
       * 从request中获取ip地址
       *
       * @param request
       * @return
       */
      public String getIpAddress(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_IP");
          }
          if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
              ip = request.getRemoteAddr();
          }
          return ip;
      }
  }
  