Forum Discussion
Extracting http header- Client IP address
@Xuwen : Many Thanks for your reply ! So I have consolidated your code along with logging the traffic with minor changes. I have also replaced the "HTTP::header insert "Client_Real_IP" $client_ip" TO "HTTP::header replace "X-Forwarded-For" $client_ip" as that will be inserting another IP header which I am thinking will not server the purpose, because the application guys are looking only or what is in the X-Forwarder-for header. What do you think about this ?
when HTTP_REQUEST {
if { [HTTP::header exists "Incap-Client-IP"] } {
set client_ip [HTTP::header "Incap-Client-IP"]
log local0. [HTTP::header "Incap-Client-IP"]
} elseif { [HTTP::header exists "X-Forwarded-For"] } {
set client_ip [getfield [HTTP::header "X-Forwarded-For"] "," 1]
log local0. [getfield [HTTP::header "X-Forwarded-For"] "," 1]
}
if { [info exists client_ip] } {
HTTP::header replace "X-Forwarded-For" $client_ip
}
}
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