Forum Discussion
René_Posthumus
Altostratus
Dec 22, 2020iRules: Putting the source port of a client in a HTTP header to a backend for logging
Hi everybody, I'm up to a challenge. We need to be able to record the source IP and port of a client to do some extra logging, but i'm missing something, or maybe it's not possible at all. I got t...
René_Posthumus
Altostratus
Dec 22, 2020Figured out myself using some other posts, i had to use CLIENT_ACCEPTED instead of SERVER_CONNECTED event. Now it works fine! 😀
So to be complete, this is the code:
when CLIENT_ACCEPTED {
set clientsourceport [TCP::client_port]
set curtime [clock seconds]
set formattedtime [clock format $curtime -format {%T} ]
set client_ip [IP::client_addr]
log local0. "Connection on $formattedtime from $client_ip with source port $clientsourceport."
}
when HTTP_REQUEST {
HTTP::header insert X-Client-Source-Port "$clientsourceport"
log local0. "Request headers [HTTP::request]"
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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