ã¯ã©ã¤ã¢ã³ãã®IPã¢ãã¬ã¹ãå¾ã
Servletã«ã¢ã¯ã»ã¹ãã¦ããã¯ã©ã¤ã¢ã³ãã®IPã¢ãã¬ã¹ãå¾ãæ¹æ³ã
ãããã·ãä»ããªãå ´å
ServletRequest#getRemoteAddr()ã§ãã¢ã¯ã»ã¹ãã¦ããã¯ã©ã¤ã¢ã³ãã®IPã¢ãã¬ã¹ãåå¾ã§ãã¾ãã
ServletRequest request = .. çç¥ .. // ã¯ã©ã¤ã¢ã³ãã®IPã¢ãã¬ã¹( ãããã·ãä»ãå ´åããããã·ã®IPã¢ãã¬ã¹ ) String proxyIp = request.getRemoteAddr();
ãããã·ãä»ããå ´å
ServletRequest#getRemoteAddr()ã¯ããããã·ãµã¼ãã¼ã®IPã¢ãã¬ã¹ãè¿ãã¾ããã¾ãããããã·ãµã¼ãã¼ã§ã¯ã©ã¤ã¢ã³ãIPã¢ãã¬ã¹ãè¿ãè¨å®ãããã¦ããã°ãç°å¢å¤æ°ã§æ¬æ¥ã®ã¯ã©ã¤ã¢ã³ãã®IPã¢ãã¬ã¹ã渡ããã¾ããããã解æããã°ã¨ããªãã¯ãªãã§ãã
- Ãéä¿¡ããªãè¨å®ã®å ´åãå½ç¶éä¿¡ãããªãã(社å ãããã·ãªããã§ã¯ã»ãã¥ãªãã£çã«æ®ééä¿¡ããªãããªã¼ã)
- Ããããã·ãµã¼ãã¼ãã¨ã«æåãç°ãªãããããããã·ãã¨ã«è§£æã³ã¼ããç¨æããå¿ è¦ãããã
ä¾ãã°ãsquidã§ã¯HTTP_X_FORWARDED_FOR ç°å¢å¤æ°ã«ä¿åãããã®ã§ã次ã®ãããªã³ã¼ãã§åå¾ã§ãã¾ãã
ServletRequest request = .. çç¥ .. // ãããã·ãä»ãã¦ã¢ã¯ã»ã¹ããã¯ã©ã¤ã¢ã³ãã®IPã¢ãã¬ã¹ HttpServletRequest hr = (HttpServletRequest) request; String clientIp = hr.getHeader( "x-forwarded-for" ); // å¤æ®µãããã·ã®å ´åãèæ ®ãã¦ããªãã®ã§æ³¨æã
åè: