public static List < String > getRemoteAddresses ( HttpServletRequest request ) { List < String > addresses = new ArrayList < String > ( ) ; addresses . add ( request . getRemoteHost ( ) ) ; if ( ! request . getRemoteAddr ( ) . equals ( request . getRemoteHost ( ) ) ) { // Store both remote host and remote address addresses . add ( request . getRemoteAddr ( ) ) ; } final String forwardedFor = request . getHeader ( "X-Forwarded-For" ) ; if ( forwardedFor != null ) { // Also store address this request was forwarded for. final String [ ] parts = forwardedFor . split ( "," ) ; for ( String part : parts ) { addresses . add ( part ) ; } } final String httpVia = request . getHeader ( "Via" ) ; if ( httpVia != null ) { // Also store address this request was forwarded for. final String [ ] parts = httpVia . split ( "," ) ; for ( String part : parts ) { addresses . add ( part ) ; } } return Collections . unmodifiableList ( addresses ) ; }
Return all remote addresses that were involved in the passed request .