Forum Discussion
hosting-team_36
Nimbostratus
Oct 29, 2018irule to extract single IP from X-Forwarded-for results with multiple IPs
I need an irule to split the IP::remote_addr and just set the first IP as theX-Forwarded-For
when HTTP_REQUEST {
HTTP::header insert X-Forwarded-For [IP::remote_addr]
}
https://devcentral.f5.com/...
Kevin_Stewart
Employee
Oct 30, 2018Ah, ok. Wasn't sure how [IP::remote_addr] was involved.
An X-Forwarded-For header with multiple IPs will be comma-delimited:
X-Forwarded-For: 10.10.0.1, 10.10.0.2, 10.10.0.3
So to grab the first one, you can do some simple list manipulation:
if { [HTTP::header "X-Forwarded-For"] ne "" } {
if { [HTTP::header "X-Forwarded-For"] contains "," }{
set ips [split [HTTP::header "X-Forwarded-For"] ","]
set xff [lindex ${ips} 0]
} else {
set xff [HTTP::header "X-Forwarded-For"]
}
} else {
set xff [IP::remote_addr]
}
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects