Forum Discussion
RED/GREEN/BLURE OVA servers for demo lab
- Aug 15, 2022
Instead of using using webservers I prefer to have some virtual servers running on a 2nd BIG-IP that will respond like webservers.
The replies are send by an iRule like this:
when HTTP_REQUEST { set cookielist "" foreach cookieinfo [HTTP::header values "Cookie:"] { append cookielist [string map -nocase {"; " "<br/>"} $cookieinfo] } if {[HTTP::cookie exists TestSessionID]} { set sessionid "TestSessionID=[HTTP::cookie value TestSessionID]" } else { set sessionid "TestSessionID=[format %09d [expr int(rand()*1e9)]].[format %09d [expr int(rand()*1e9)]]" } # use standard color names, i.e. "Blue", "Red", "Green", "Yellow", "Brown", "White", "Magenta", "Pink", "Gray" set servercolor "Blue" if {[string tolower [HTTP::uri]] starts_with "/text"} { set page \ "Server \[IP::local_addr\]:\[TCP::local_port\]\t[IP::local_addr]:[TCP::local_port] \[IP::client_addr\]:\[TCP::client_port\]\t[IP::client_addr]:[TCP::client_port] \[HTTP::host\]\t\t\t\t[HTTP::host] \[HTTP::uri\]\t\t\t\t[HTTP::uri] \[HTTP::path\]\t\t\t\t[HTTP::path] \[HTTP::query\]\t\t\t\t[HTTP::query] \[HTTP::header X-Forwarded-For\]\t\t[HTTP::header X-Forwarded-For] \[HTTP::header Virtual-Server-IP\]\t\t[HTTP::header Virtual-Server-IP] \[HTTP::header X-Offloaded-SSL\]\t\t[HTTP::header X-Offloaded-SSL] Random Number\t\t\t\t[format %04d [expr int(rand()*1e4)]]\n" } else { set page \ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"> <html><head><title>Server $servercolor</title></head> <body text=#000000 bgcolor=$servercolor> <h2><font face=Verdana>Server $servercolor</font></h2> <font face=Verdana><table border cellpadding=2 bgcolor=#C0C0C0> <tr><td>\[IP::local_addr\]:\[TCP::local_port\]</td><td>[IP::local_addr]:[TCP::local_port] </td></tr> <tr><td>\[IP::client_addr\]:\[TCP::client_port\]</td><td>[IP::client_addr]:[TCP::client_port] </td></tr> <tr><td>\[HTTP::host\]</td><td>[HTTP::host] </td></tr> <tr><td>\[HTTP::uri\]</td><td>[HTTP::uri] </td></tr> <tr><td>\[HTTP::path\]</td><td>[HTTP::path] </td></tr> <tr><td>\[HTTP::query\]</td><td>[HTTP::query] </td></tr> <tr><td>\[HTTP::header X-Forwarded-For\]</td><td>[HTTP::header X-Forwarded-For] </td></tr> <tr><td>\[HTTP::header Virtual-Server-IP\]</td><td>[HTTP::header Virtual-Server-IP] </td></tr> <tr><td>\[HTTP::header X-Offloaded-SSL\]</td><td>[HTTP::header X-Offloaded-SSL] </td></tr> <tr><td>Clientside Cookies:</td><td>$cookielist </td></tr> <tr><td>Random Number:</td><td><font color=red>[format %04d [expr int(rand()*1e4)]] </font></td></tr> </table></font></body></html>" } HTTP::respond 200 -version auto content "$page" noserver Set-Cookie $sessionid Server "$servercolor" Date "[clock format [clock seconds] -format {%a, %b %d %Y %H:%M:%S GMT} -gmt 1]" event disable return }
This one can easily be enhanced to mirror different request parameters.
It works as well for cURL with plain text replies:
# curl http://10.131.131.184/text/testpath?param=queryparam -H 'Host: app3.lb-net.bit' -sv * Trying 10.131.131.184... * Connected to 10.131.131.184 (10.131.131.184) port 80 (#0) > GET /text/testpath?param=queryparam HTTP/1.1 > Host: app3.lb-net.bit > User-Agent: curl/7.47.1 > Accept: */* > < HTTP/1.1 200 OK < Set-Cookie: TestSessionID=123988933.882004550 < Server: Blue < Date: Mon, Aug 15 2022 17:50:31 GMT < Connection: Keep-Alive < Content-Length: 385 < Server [IP::local_addr]:[TCP::local_port] 10.131.131.184:80 [IP::client_addr]:[TCP::client_port] 10.131.131.181:43618 [HTTP::host] app3.lb-net.bit [HTTP::uri] /text/testpath?param=queryparam [HTTP::path] /text/testpath [HTTP::query] param=queryparam [HTTP::header X-Forwarded-For] [HTTP::header Virtual-Server-IP] [HTTP::header X-Offloaded-SSL] Random Number 8504
Instead of using using webservers I prefer to have some virtual servers running on a 2nd BIG-IP that will respond like webservers.
The replies are send by an iRule like this:
when HTTP_REQUEST {
set cookielist ""
foreach cookieinfo [HTTP::header values "Cookie:"] {
append cookielist [string map -nocase {"; " "<br/>"} $cookieinfo]
}
if {[HTTP::cookie exists TestSessionID]} {
set sessionid "TestSessionID=[HTTP::cookie value TestSessionID]"
}
else {
set sessionid "TestSessionID=[format %09d [expr int(rand()*1e9)]].[format %09d [expr int(rand()*1e9)]]"
}
# use standard color names, i.e. "Blue", "Red", "Green", "Yellow", "Brown", "White", "Magenta", "Pink", "Gray"
set servercolor "Blue"
if {[string tolower [HTTP::uri]] starts_with "/text"} {
set page \
"Server
\[IP::local_addr\]:\[TCP::local_port\]\t[IP::local_addr]:[TCP::local_port]
\[IP::client_addr\]:\[TCP::client_port\]\t[IP::client_addr]:[TCP::client_port]
\[HTTP::host\]\t\t\t\t[HTTP::host]
\[HTTP::uri\]\t\t\t\t[HTTP::uri]
\[HTTP::path\]\t\t\t\t[HTTP::path]
\[HTTP::query\]\t\t\t\t[HTTP::query]
\[HTTP::header X-Forwarded-For\]\t\t[HTTP::header X-Forwarded-For]
\[HTTP::header Virtual-Server-IP\]\t\t[HTTP::header Virtual-Server-IP]
\[HTTP::header X-Offloaded-SSL\]\t\t[HTTP::header X-Offloaded-SSL]
Random Number\t\t\t\t[format %04d [expr int(rand()*1e4)]]\n"
} else {
set page \
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\">
<html><head><title>Server $servercolor</title></head>
<body text=#000000 bgcolor=$servercolor>
<h2><font face=Verdana>Server $servercolor</font></h2>
<font face=Verdana><table border cellpadding=2 bgcolor=#C0C0C0>
<tr><td>\[IP::local_addr\]:\[TCP::local_port\]</td><td>[IP::local_addr]:[TCP::local_port] </td></tr>
<tr><td>\[IP::client_addr\]:\[TCP::client_port\]</td><td>[IP::client_addr]:[TCP::client_port] </td></tr>
<tr><td>\[HTTP::host\]</td><td>[HTTP::host] </td></tr>
<tr><td>\[HTTP::uri\]</td><td>[HTTP::uri] </td></tr>
<tr><td>\[HTTP::path\]</td><td>[HTTP::path] </td></tr>
<tr><td>\[HTTP::query\]</td><td>[HTTP::query] </td></tr>
<tr><td>\[HTTP::header X-Forwarded-For\]</td><td>[HTTP::header X-Forwarded-For] </td></tr>
<tr><td>\[HTTP::header Virtual-Server-IP\]</td><td>[HTTP::header Virtual-Server-IP] </td></tr>
<tr><td>\[HTTP::header X-Offloaded-SSL\]</td><td>[HTTP::header X-Offloaded-SSL] </td></tr>
<tr><td>Clientside Cookies:</td><td>$cookielist </td></tr>
<tr><td>Random Number:</td><td><font color=red>[format %04d [expr int(rand()*1e4)]] </font></td></tr>
</table></font></body></html>"
}
HTTP::respond 200 -version auto content "$page" noserver Set-Cookie $sessionid Server "$servercolor" Date "[clock format [clock seconds] -format {%a, %b %d %Y %H:%M:%S GMT} -gmt 1]"
event disable
return
}
This one can easily be enhanced to mirror different request parameters.
It works as well for cURL with plain text replies:
# curl http://10.131.131.184/text/testpath?param=queryparam -H 'Host: app3.lb-net.bit' -sv
* Trying 10.131.131.184...
* Connected to 10.131.131.184 (10.131.131.184) port 80 (#0)
> GET /text/testpath?param=queryparam HTTP/1.1
> Host: app3.lb-net.bit
> User-Agent: curl/7.47.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Set-Cookie: TestSessionID=123988933.882004550
< Server: Blue
< Date: Mon, Aug 15 2022 17:50:31 GMT
< Connection: Keep-Alive
< Content-Length: 385
<
Server
[IP::local_addr]:[TCP::local_port] 10.131.131.184:80
[IP::client_addr]:[TCP::client_port] 10.131.131.181:43618
[HTTP::host] app3.lb-net.bit
[HTTP::uri] /text/testpath?param=queryparam
[HTTP::path] /text/testpath
[HTTP::query] param=queryparam
[HTTP::header X-Forwarded-For]
[HTTP::header Virtual-Server-IP]
[HTTP::header X-Offloaded-SSL]
Random Number 8504
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