Forum Discussion
dragonflymr
Cirrostratus
Dec 07, 2015Parsing IP to extract subnet
Hi,
I wonder if there is more elegant and fastest way to extract specific part of IP - like get only part of IP up to second dot, third dot.
I know that I can use scan to separate IP in fou...
dragonflymr
Cirrostratus
Dec 08, 2015Hi,
First of all, thanks for help. Second, it was my fault. I did not describe my goal precise enough. Idea is to create keys (for tables or iStats) using variable mask (depending on some iRule logic). IPs are not know in advance and right now there is no idea of using them for some if or switch operations.
Below my crude iRule that should shed some light on what I mean - at least I hope so 🙂
when CLIENT_ACCEPTED {
set addr [IP::client_addr]
log local0. "Client IP: $addr"
scan $addr {%d.%d.%d.%d} a b c d
}
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"*/24" {
set newaddr "$a.$b.$c.0"
set uri [string map -nocase {"/24" "/"} [HTTP::uri]]
HTTP::uri $uri
}
"*/16" {
set newaddr "$a.$b.0.0"
set uri [string map -nocase {"/16" "/"} [HTTP::uri]]
HTTP::uri $uri
}
"*/8" {
set newaddr "$a.0.0.0"
set uri [string map -nocase {"/8" "/"} [HTTP::uri]]
HTTP::uri $uri
}
default {
set newaddr $addr
}
}
log local0. "scan result: $newaddr"
ISTATS::incr "ltm.virtual [virtual name] c $newaddr" 1
}
Point is if I can perform subnet creation in some more elegant, faster way that the one above (scan cmd).
Piotr
dragonflymr
Cirrostratus
Dec 08, 2015Well, probably I found solution - question is if it's the best use something like that:
set sub_var [IP::addr [IP::client_addr] mask 255.255.0.0]
and adjusting mask parameter as needed - is that right track. I am a bit lost how to use IP:addr
Piotr
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