在java中獲取客戶端真實的IP地址

  1. public static String getRemoteAddress(HttpServletRequest request){   
  2.     String ip = request.getHeader("x-forwarded-for");   
  3.     if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getHeader("Proxy-Client-IP");   
  4.     if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getHeader("WL-Proxy-Client-IP");   
  5.     if(ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) ip = request.getRemoteAddr();   
  6.     return ip;   
  7. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章