Forum Discussion
Mauricio_Cusine
Nimbostratus
Aug 22, 2007Validate IP address with regexp
Hello,
I am trying to check if a IP address is valid in the bigip with regexp (I don't know if anybody know other method).
The regexp is the follow but don't work. Anybody can help me?.
I need to check if the ip address is in the range 1-255 in the 4 octects.
King regards,
Mauro
regexp
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
13 Replies
- Thomas_Schaefer
Nimbostratus
Does anyone have an idea why this would not work with 209.162.186.60 pulled from a string? I am executing this statement:
set a "209.162.186.60"
log local0. "catch $a => [catch {IP::addr $a mask 255.255.255.255} ]"
log local0. "catch $hostname => [catch {IP::addr $hostname mask 255.255.255.255} ]"
log local0. "hostname = \[$hostname>\]"
$hostname was pulled from a header using set hostname [HTTP::header "X-HOSTNAME"].
This is the result of the log:
Rule OutboundSSLRouter HTTP_REQUEST: catch 209.162.186.60 = 1
Rule OutboundSSLRouter HTTP_REQUEST: catch 209.162.186.60 = 0
Rule OutboundSSLRouter HTTP_REQUEST: catch 209.162.186.60 = 1
Is there anything special about a variable pulled from HTTP::header? - Luke_Lehman
Employee
I'm seeing what looks like the same problem the above poster is seeing. I'm base64 decoding a portion of the URI, and the catch sees an exception with the decoded variable value, but doesn't have an exception from a recently declared string value:
set a 256.256.256.256
set b 192.168.199.156
set c 192.168.199.157
if {[catch {b64decode $query_b64encoded_member_ip} b64decoded_member_ip] == 0 and $b64decoded_member_ip ne ""}{
base64 decoding succeeded
if { $::debug } {log local0. "b64 decoding successful: $b64decoded_member_ip"}
}
log local0. "catch $a => [catch {IP::addr $a mask 255.255.255.255} ]"
log local0. "catch $b64decoded_member_ip => [catch {IP::addr $b64decoded_member_ip mask 255.255.255.255} ]" log local0. "catch $b => [catch {IP::addr $b mask 255.255.255.255} ]"
log local0. "catch $c => [catch {IP::addr $c mask 255.255.255.255} ]"
Logged Output:
Rule gen_iRule : b64 decoding successful: 192.168.130.156
Rule gen_iRule : catch 256.256.256.256 => 1
Rule gen_iRule : catch 192.168.199.156 => 1
Rule gen_iRule : catch 192.168.199.156 => 0
Rule gen_iRule : catch 192.168.199.157 => 0
You can see that the .156 address from the base64 decoded value fails the IP:addr check, whereas the pure string variable $c passes fine.
Curious. - hoolio
Cirrostratus
Hi Luke,
I'm not sure what would cause this. Can you open a case with F5 Support and reply back here with the case number? I'm interested to see what happens.
Thanks, Aaron
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
