Block Country

From Tech-Wiki
Revision as of 15:55, 20 May 2019 by Fabricio.Lima (Talk | contribs) (Created page with "Category:F5 Networks '''Back to iRules''' # negative logic when CLIENT_ACCEPTED { # Get the country client IP switch [whereis [IP::clien...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Back to iRules

# negative logic
when CLIENT_ACCEPTED {
   # Get the country client IP 
   switch [whereis [IP::client_addr] country] {
       "CN" -
       "RU" {
           set allowed 0
       }
       default { set allowed 1 }
   }
}
when HTTP_REQUEST {
   if {$allowed == 0}{
       HTTP::respond 403 content {Blocked!}
   }
}
# positive logic 
when CLIENT_ACCEPTED {
   # Get the country client IP 
   switch [whereis [IP::client_addr] country] {
       US -
       CA -
       MX {
           set allowed 1
       }
       default { set allowed 0 }
   }
}
when HTTP_REQUEST {
   if {$allowed == 0}{
       HTTP::respond 403 content {Blocked!}
   }
}