For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

jona187_168823's avatar
jona187_168823
Icon for Nimbostratus rankNimbostratus
Mar 04, 2015

iRule to set country code for IP

I need help setting the country code for a specific IP to test out website functionality

 

I want to create an irule to set the country code to a specific country, fo ex like CN

 

What is the keyword to call the country

 

would it be

 

set country = "CN"

 

or would it be

 

set ([whereis [IP::client_addr] country] eq "CN" )

 

5 Replies

  • Have you seen this question? It may help a little bit (though I don't know if you can "set" the whereis value (unless you know of an IP in the expected country and use that instead of IP::client_addr).

  • Perhaps the safest option would be expanding your IF condition with an OR statement (using the [IP::client_addr] function, as recommended by Michael J)

     

    when HTTP_REQUEST {
    
    
      if { ([whereis [IP::client_addr]] == "CN") || ([IP::client_addr] == "Your.IP.Address" ) } {
        do some stuff...
      }
    }

    Alternatively, you should be able to set the system-provided 'whereis' variable to your own value. Have not tested, please use with caution

     

    when HTTP_REQUEST {
    
    
      if { [IP::client_addr] == "Your.IP.Address"} {
        set [whereis [IP::client_addr]] "CN"
        For verification, tail /var/log/ltm as you implement the changes
        log local0. "IP: [IP::client_addr]; Country Code: [whereis [IP::client_addr]]"
      }
    
       Geo-location iRule continues...
    
    }
    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus
      Please note there's an error, you should use "[whereis [IP::client_addr] country]" everywhere, instead of "[whereis [IP::client_addr]]"
    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      is set [whereis [IP::client_addr] country] "CN" typo?
  • I'm pretty sure that the whereis function is read-only, so you can't do any kind of setting the value. Based on your original question of wanting to test, then your best bet may be to just use a variable and set it manually

     

    when HTTP_REQUEST {
        if {[IP::client_addr] == "Your.IP.Address"} {
            set country "CN"
        } else {
            set country [whereis [IP::client_addr] country]
        }
    
        For verification, tail /var/log/ltm as you implement the changes
        log local0. "IP: [IP::client_addr]; Country Code: $country"
    
         Geo-location iRule continues...
           Use the "$country" variable instead of "whereis" from now on.        
    }