Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help for iRule To Block Specific URL

PUTMANO_KEO
Nimbostratus
Nimbostratus

We have our website abc.com and we would like to block the specific like abc.com/123/ which access from Japan. I try to find some trick to write the iRule but it's not access. Anybody here can me on this? I tried something like the iRule below but it still no luck.

 

when HTTP_REQUEST {

  if { [HTTP::header exists "X-Forwarded-For"] } {

     set client_ip [HTTP::header value "X-Forwarded-For"]

     set fromCountry [whereis $client_ip country]

     if { ( [class match $fromCountry equals example_datagroup]) }{

        log local0. "Attacker IP in XFF [HTTP::header X-Forwarded-For]" ;# This can be removed/commented out if not required

        HTTP::respond 403 content "Blocked!" ;# This can also be changed to drop or reject based on the requirement

    }

  }

}

2 REPLIES 2

Samir
MVP
MVP

Try below iRule. Hope it will work for you.. thanks

when HTTP_REQUEST {
   set fromCountry [whereis [IP::client_addr] country]
   if { ([class match $fromCountry equals example_datagroup]) && ([HTTP::uri]] starts_with "/abc") } {
     log local0. "Attacker IP in XFF [HTTP::header X-Forwarded-For]" ;# This can be removed/commented out if not required
      HTTP::respond 403 content "Blocked!" ;# This can also be changed to drop or reject based on the requirement
   }
}

crodriguez
Legacy Employee
Legacy Employee

Are you trying to block access based on a URL, such as abc.com/123/, or are you trying to block access based on the client's geolocation, as determined by the IP address provided in the HTTP X-Forwarded-For header?