public static String extractClientIpFromXForwardedFor ( String xForwardedFor ) { if ( xForwardedFor == null ) { return null ; } xForwardedFor = xForwardedFor . trim ( ) ; String tokenized [ ] = xForwardedFor . split ( "," ) ; if ( tokenized . length == 0 ) { return null ; } else { return tokenized [ 0 ] . trim ( ) ; } }
Extract the client IP address from an x - forwarded - for header . Returns null if there is no x - forwarded - for header