Forum Discussion
breizho35_11667
Nimbostratus
Feb 08, 2010How to read source IP and write http header ?
Hello,
since commencing in iRules, I seek your help to write a script to meet this need:
How to read source IP and write http header ?
when HTTP_Request (
- Read source IP address (eg 192.168.100.101) and translate this source IP in a digit code number of 10 characters without point (eg 2168100101)
- Include a http header corresponding to this digit code (eg TOTO: 1234567890).
HTTP::header insert "TOTO" "digit code"
}
Please, can you help me to write this script?
Thanks you for your help,
Eric
- The_Bhattman
Nimbostratus
Hi Eric,when HTTP_REQUEST { Create the variable that will be used to later to store the IP address with the dots set ipaddr Scan command looks at the source address in [IP::client] and breaks it up into 4 variables oct1 to oct4 scan [IP::client] {%[^.].%[^.].%[^.].%s} oct1 oct2 oct3 oct4 append takes all the variables oct1 to oct4 and puts them together into another variable called ipaddr append $ipaddr $oct1 $oct2 $oct3 $oct4 The command below inserts a header called TOTO with the value of what's in ipaddr [HTTP::header] insert "TOTO" $ipaddr }
- hoolio
Cirrostratus
I think the poster is trying to convert the client IP to a decimal value, along the lines of the PHP ip2long function. I was playing around with such a conversion in TCL, but it seems to overflow a 2^32 integer: - hoolio
Cirrostratus
Actually, maybe not. Maybe he just wants the periods removed and to take the last 10 characters? If so, something like this should work too:when CLIENT_ACCEPTED { Remove the .'s from the client IP and take the last 10 digits set ip_string [string map {"." ""} [IP::client_addr]] set ip_string [string range $ip_string [expr {[string length $ip_string] - 10}] end] } when HTTP_REQUEST { Insert the HTTP header HTTP::header replace TOTO $ip_string }
- breizho35_11667
Nimbostratus
Hello,
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