Forum Discussion

Bciesz_171056's avatar
Aug 21, 2017

iRule if based on incoming IP

Hi,

I have a problem here... I'm trying to make an iRule perform specific action if incoming traffic comes from a specific IP address. I have:

 

if {[IP::addr [IP::client_addr] equals 10.8.199.231]}{
    log local0. "dupa"
}

 

now I'm quite sure my IP is 10.8.199.231 but when I log this traffic using:

log local0. "Incoming IP: [IP::client_addr]"

i get in log:

10.8.199.231%3

How can I catch traffic from this IP to code some exceptions?

4 Replies

  • I guess the %3 is added because you are using multiple route domains.

     

    If you add to your condition equals "10.8.199.231%3"

     

    It will match

     

    Regards

     

  • Did you refer this Q&A and Q&A.

    So it would be something like below,

     

    set rd "%[ROUTE::domain]"
    set client_ip [string map "$rd \"\"" [IP::client_addr]]
    if {$client_ip equals "10.8.199.231"} {
        log local0. "IDMS dupa"
    } 
    

     

  • Hi,

    you can extract Route domain and IP Address with split and compare it with IP::addr (useful if you need to compare network with netmask evaluation)

     

    elseif {$incURI contains "csmon"}{
        set _redirect "0"
        log local0. "IDMS test Monitoring: [HTTP::uri]"
        log local0. "IDMS test inc IP: [IP::client_addr]"
        lassign [split [IP::client_addr] "%"] IP_addr rd
        if {[IP::addr $IP_addr equals "10.8.199.231"] && $rd equals [ROUTE::domain]} {
            log local0. "IDMS dupa"
        }   
    }