Forum Discussion
Deon
Nimbostratus
Jan 06, 2009How To Concatenate Strings
OK, Newbie here. Trying to figure out how to concatenate strings properly in an iRule. Ive got the following code and the newaddr value is not being formatted like I expect.
when HTTP_RESPONSE {
set addr [IP::server_addr]
log local0. $addr
set c [getfield $addr "." 3]
set d [getfield $addr "." 4]
set newaddr [concat "1.1." $c "." $d]
log local0. $newaddr
HTTP::header insert "Server_ID" [IP::server_addr]
}
The intent of the iRule is to insert a somewhat obfuscated IP address of the member server as a header tag in the response. So, if the member server IP is 10.44.6.11, the desired tag value inserted would be "1.1.6.11". The result I am getting is "1.1. 6 . 11 ". How do I strip out the spaces around the vars c and d? Is there a better or more desirable way to do this than the code I've got here?
Thanks much!
-Deon
- hoolio
Cirrostratus
Hi Deon,when RULE_INIT { set addr [IP::server_addr] set addr "111.222.333.444" log local0. "Original \$addr: $addr" Scan the address for four digits separated by periods scan $addr {%d.%d.%d.%d} a b c d Take the third and fourth octets and combine them with the static first two octets. set newaddr "1.1.$c.$d" log local0. "scan result: $newaddr" }
- Deon
Nimbostratus
Excellent. I had a feeling I was taking a long route when trying to do the concatenation. Thanks much for your help!
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