Forum Discussion
Extract 2nd to last IP from X-FORWARDED-FOR header
- Dec 12, 2019
Just as a final in case anyone stubles over my query I did find an issue when trying to match the variable to a datagroup that there is a leading space preventing matching (attempts to set the split to work on ", " didnt seem to work), so I had to add a line to remove this with a string map. Example irule logging the whole X-FWD-FOR header, client IP as seen my the F5 and the "real client IP" as seen by the WAF
when HTTP_REQUEST {
set RealClientIP [lindex [split [HTTP::header X-Forwarded-For] ","] end-1]
set RealClientIP [string map {" " ""} $RealClientIP]
log local0. " X-Forwarded-For: [HTTP::header X-Forwarded-For] Client IP [IP::client_addr] Real Client IP: $RealClientIP "
}
May have answered my own question:
set RealClientIP [lindex [split [HTTP::header X-Forwarded-For] ","] end-1]
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com