×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Boulty Doolin
Added: Sep 28, 2017 2:06 PM
Modified: Sep 28, 2017 2:23 PM
Views: 3
Gets the remote IP address of a HTTP request
  1. import javax.servlet.http.HttpServletRequest;
  2.  
  3. public class TempWrapper {
  4.    
  5.     public String getIPAddress(HttpServletRequest  request) {
  6.         String ipAddress = request.getHeader("X-FORWARDED-FOR");
  7.         if (ipAddress == null)
  8.         {
  9.             ipAddress = request.getRemoteAddr();
  10.         }
  11.         return ipAddress;
  12.     }
  13. }
  14.