Forum Discussion

rexmcordero_144's avatar
rexmcordero_144
Icon for Nimbostratus rankNimbostratus
Sep 29, 2015

Return a page when a port is accessed

Hi,

 

I want to create an iRule that if a specific port is accessed, it will return a page like "You used port 143, please use 8080".

 

when CLIENT_ACCEPTED {

 

if { [TCP::local_port] == 143 } {

 

HTTP::respond 200 content { Test You used port 143, please use 8080. } }

 

}

 

Thanks Much much!

 

2 Replies

  • Lucas_Thompson_'s avatar
    Lucas_Thompson_
    Historic F5 Account

    You're 99% there. Just have to remember that you're not in HTTP yet. CLIENT_ACCEPTED happens in TCP, so you have to use TCP::respond instead of HTTP::respond. You can also send a response and close the connection before the client has actually transmitted the request, it's tolerated OK. For example:

     

    TCP::respond "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\nPlease connect to port 8080 instead of port [TCP::local_port]"

     

  • Hi,

    If the VS is defined with * service port, create another VS with port 143 and profile HTTP.

    enable the following irule on this VS:

    when HTTP_REQUEST {
    HTTP::respond 200 content " You used port 143, please use 8080."
    }