방문 한 사용자 의 실제 IP 가 져 오기



 JSP ,      IP      :request.getRemoteAddr(),                。      Apache,Squid                   IP   。 
               , http://192.168.1.110 :2046/  URL      http://www.xxx.cn /  URL , request.getRemoteAddr()     IP   :127.0.0.1   192.168.1.110,          IP。 
          ,                 ,                IP,                           。        HTTP    ,   X-FORWARDED-FOR  。          IP                。     http://www.5555.cn /index.jsp/  ,                     index.jsp  ,            http://192.168.1.110 :2046/index.jsp ,                      ,           index.jsp ,  index.jsp    request.getRemoteAddr()      IP            ,       IP  。 
                IP      : 

public String getRemortIP(HttpServletRequest request) {   
  if (request.getHeader("x-forwarded-for") == null) {   
   return request.getRemoteAddr();   
  }   
  return request.getHeader("x-forwarded-for");   
 }   

public String getRemortIP(HttpServletRequest request) {
  if (request.getHeader("x-forwarded-for") == null) {
   return request.getRemoteAddr();
  }
  return request.getHeader("x-forwarded-for");
 } 

          http://www.5555.cn /index.jsp/  ,   IP     unknown,         127.0.0.1   192.168.1.110 ,    http://192.168.1.110 :2046/index.jsp  ,          IP  ,        。     Squid 。squid.conf       forwarded_for      on,   forwarded_for     off   :X-Forwarded-For: unknown 
                IP      : 

public 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.getRemoteAddr();   
       }   
       return ip;   
   }   

public 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.getRemoteAddr();
       }
       return ip;
   } 


      ,             ,X-Forwarded-For       ,    Ip ,               IP ? 
        X-Forwarded-For     unknown   IP   。 
     :X-Forwarded-For:192.168.1.110, 192.168.1.120, 192.168.1.130, 192.168.1.100    IP : 192.168.1.110 




좋은 웹페이지 즐겨찾기