Forum Discussion
Dayton_Gray_103
Nimbostratus
Oct 18, 2006Limiting connections base on user-agent and URI
I am wondering if anyone has an examples or can point me in the right direction as to how I would go about limiting connections based on the HTTP::header User-Agent and based on HTTP::uri. I'm basical...
John_Pope_42012
Nimbostratus
Oct 30, 2007from the irule runner up winner Eduardo Saito
irule_limit_num_connections_googlebot
http://devcentral.f5.com/Default.aspx?tabid=109
when RULE_INIT {
array set ::active_clients { }
}
when CLIENT_ACCEPTED {
switch -glob [string tolower [HTTP::header "User-Agent"]] {
"*googlebot*" {
set client_ip [IP::remote_addr]
if { [info exists ::active_clients($client_ip)] } {
if {$::active_clients($client_ip) > 10 } {
reject
log local0. "Reject GOOGLEBOT IP $client_ip ($::active_clients($client_ip))"
return
} else {
incr ::active_clients($client_ip)
}
} else {
set ::active_clients($client_ip) 1
}
}
}
}
when CLIENT_CLOSED {
switch -glob [string tolower [HTTP::header "User-Agent"]] {
"*googlebot*" {
set client_ip [IP::remote_addr]
if { [info exists ::active_clients($client_ip)] } {
incr ::active_clients($client_ip) -1
if { $::active_clients($client_ip) <= 0 } {
unset ::active_clients($client_ip)
}
}
}
}
}
After copying and pasting directly into irules editor I get the two errors at both Client_accepted & CLIENT_CLOSED
command is not valid in current event context ((Client_accepted)) [HTTP:header "User-agent"]
Do I need to upgrade bigip version or..... ?
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects