Forum Discussion
Joel_42834
Nimbostratus
Oct 19, 2012IP Address Validation with CIDR
How can a validate an IP address that is stored in a string data group that uses CIDR notation?
For dotted netmasks I use: [IP::addr $address mask $netmask]
where $address is say "...
nitass
Employee
Oct 19, 2012[root@ve10:Active] config b rule myrule list
rule myrule {
when CLIENT_ACCEPTED {
foreach elm [class get cidr_class] {
if { [scan [lindex $elm 0] {%[^/]/%d} ip mask] == 2 } {
set mask [expr {~ 0 << ( 32 - $mask )}]
set mask_num [format "%d.%d.%d.%d" [expr {$mask >> 24 & 255}] [expr {$mask >> 16 & 255}] [expr {$mask >> 8 & 255}] [expr {$mask & 255}]]
log local0. "\[IP::addr [lindex $elm 0]\] = [IP::addr $ip mask $mask_num]"
}
}
}
}
[root@ve10:Active] config cat /var/log/ltm
Oct 20 00:52:16 local/tmm info tmm[7926]: Rule myrule : [IP::addr 1.1.1.1/24] = 1.1.1.0
Oct 20 00:52:16 local/tmm info tmm[7926]: Rule myrule : [IP::addr 2.2.2.2/16] = 2.2.0.0
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
