Forum Discussion
Brian_Gibson_30
Nimbostratus
Feb 19, 2015Transforming an IP address via IRule
I am trying to take a client IP and convert it to a new IP using a generic IP address mask but using the last 2 octets of the client's IP.
My RegEx skills are not the greatest but this really doesn't seem that it should be that hard. So I'm not sure what I am doing wrong here as the regex seems ok. I tried to use braces on the regex but the LB said that my pattern didn't do anything then.
when CLIENT_ACCEPTED {
set clientip [IP::client_addr]
regsub "^\d+.\d+." $clientip "10.99." newip
log local0.info "value on transformed IP is $newip"
}
4 Replies
Sort By
- JRahm
Admin
better to use scan in this case:
when CLIENT_ACCEPTED { scan [IP::client_addr] %d.%d.%d.%d 0 0 o3 o4 log local0.info "value on transformed IP is 10.99.$o3.$o4" }
- JRahm
Admin
there's almost always a better way with string commands than using regex. Using regex is a very expensive operation for iRules, and should be avoided unless absolutely necessary. - Brian_Gibson_30
Nimbostratus
That does work much better. Thanks!!
- JRahm
Admin
you bet!
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