I want to send a HTTP response based on the client source IP address, it is just for a test, but the iRule validation fails. I prefer to keep it simple, I know I can add the switch clause, but for now I dont want to overcomplicate it.
Here it is:
when HTTP_REQUEST { log local0. “Client ([IP::client_addr]) is requesting: [HTTP::uri]” if { ([IP::addr [IP::client_addr]/24 equals 64.122.88.0 ]) or ([IP::addr [IP::client_addr]/24 equals 180.10.134.140.0 ]) } { log local0. “Default condition” HTTP::respond 200 content “Forbidden Redirect From Remote ServerThis is the mock up for testing” } }
This is the code I am using but not validating the client source IP addresses still:
Code
`
when HTTP_REQUEST {
log local0. "Client ([IP::client_addr]) is requesting: [HTTP::uri]"
if { ([IP::addr [IP::client_addr]/24 equals 54.179.88.0 ]) or ([IP::addr[IP::client_addr]/24 equals 17.34.134.140.0 ]) or ([IP:addr[IP::client_addr]/24 equals 219.45.252.0 ]) }
{
log local0. "Default condition"
HTTP::respond 200 content "Forbidden Redirect From Remote Server<BODY>This is the mock up for testing"
}
}
you can try this, it will be more easy to manage your client IP… As you can noticed you can add additional client IP in multivalue var or delete (it will allow you to don’t touch condition, just add or delete client IP)…
when HTTP_REQUEST {
set uri [string tolower [HTTP::uri]]
set host [string tolower [HTTP::host]]
array set client_ip {
clientip1 "64.122.88.0/8"
clientip2 "180.10.134.140.0/12"
}
foreach ip [array names client_ip] {
if { [IP::addr [IP::client_addr] equals $client_ip($ip)] } {
log local0. "client ip: [IP::client_addr] - client grp matching: $client_ip($ip) - url: $host$uri"
HTTP::respond 200 content "what's you want to display"
}
}
}