Forum Discussion

Mauricio_Cusine's avatar
Mauricio_Cusine
Icon for Nimbostratus rankNimbostratus
Aug 22, 2007

Validate 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
  • 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?
  • 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.
  • 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