Forum Discussion
Block request by IP and send an HTTP response
Just getting into iRules and I want to block a specific IP from being able to access a webpage but return an HTTP response back to the browser. I am attempting to do this, but still not quite getting it right. Can anyone offer a suggestion that would help?
when RULE_INIT {
set static::IPBlock "ServerServer Error`-999999 `
API traffic is currently blocked. Please contact your System Administrator for assistance. BLOCKBLOCK 0
DISTRIBUTION MESSSAGE "
}
when CLIENT_ACCEPTED {
if { [IP::addr [IP::client_addr] equals 172.18.33.226] } {
set clientIP [IP::client_addr]
}
when HTTP_REQUEST {
if {$clientIP eq 172.18.33.226}
HTTP::respond 200 content "${static::IPBlock}"
}
}
1 Reply
- uni
Altocumulus
The CLIENT_ACCEPTED event is not required. [IP::client_addr] is available in the HTTP_REQUEST event. There is a bracket missing after the 'if' in the HTTP_REQUEST event. You should use the IP::addr command to compare IP addresses
when HTTP_REQUEST { if {[IP::addr [IP::client_addr] equals 172.18.33.226]} { HTTP::respond 200 content "${static::IPBlock}" } }Your use of a static variable to hold the response is ok, but I would consider using an iFile, which makes it easier to manage.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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