# Telnet Proxy iRule

**URL:** <https://community.f5.com/t/telnet-proxy-irule/28303>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [February 16, 2007, 12:39pm UTC](https://community.f5.com/t/telnet-proxy-irule/28303 "2007-02-16T12:39:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Jones\_505](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Kevin\_Jones\_505](https://community.f5.com/u/Kevin_Jones_505)\
**Post date:** [February 16, 2007, 12:39pm UTC](https://community.f5.com/t/telnet-proxy-irule/28303/1 "2007-02-16T12:39:44Z")

</div>

We would like an iRule that would accept a client connection on port 23, prompt the user for the desired destination (host name or IP), and then open an associated telnet session to an external host.

Our site doesn’t allow employees to go directly to these external servers. Currently, our firewalls perform this proxy function, but they are being migrated to another platform that doesn’t support this feature.

The virtual server associated with this iRule would be a host address and not associated with any pool; it would likely do SNAT Automap also.

Generally, we guess it would be something like:

when CLIENT\_ACCEPTED {

Send Prompt Message across client connection asking client for desired destination device

}

when CLIENT\_DATA {

collect data …

if valid IP address connect to server

if valid hostname, resolve externally and then connect to server

if neither valid IP address or hostname prompt user again

}

Does this sound plausible? Any hints or help would be appreciated.

thanks

---

<div class="post-metadata">

**Author:** ![Kevin\_Jones\_505](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Kevin\_Jones\_505](https://community.f5.com/u/Kevin_Jones_505)\
**Post date:** [February 21, 2007, 8:23pm UTC](https://community.f5.com/t/telnet-proxy-irule/28303/2 "2007-02-21T20:23:43Z")

</div>

Thanks, Colin. This is a beginning. Hmm. I see your suggestion seems to include a SERVER\_CONNECTED event … and while this should happen in this application, no decisions are needed at that point. I suspect I didn’t explain the problem well or I don’t understand your solution.

The TCP::respond command looks very useful. It would seem we would have something like:

Client side connection, iRule sends prompt, gathers client input

when CLIENT\_ACCEPTED {

TCP::respond “Enter the IP address of destination site.\r\n”

TCP::collect 20

}

Once client data collected, verify whether it’s a valid IP

when CLIENT\_DATA {

set ip [regexp -inline {([:digit:]{1,3}\.){3}[:digit:]{1,3}} [TCP::payload] ]

if { [matchclass $ip equals $::validIPs] } {

node $ip

additional statement to open serverside connection if ip is valid

} else {

TCP::respond “The IP address is invalid. Hostnames are currently not supported…\r\n”

}

TCP::release

}

Now, once we have a valid IP address (I’m letting host names go for now), we would need to open a telnet connection to that device. It would seem appropriate if we could do that once the ip address is deemed valid .. just after “node” is assigned $ip.

Once the server side connection is formed, the iRule is no longer needed.

We’ll keep working on it, but I know we’ve got a bit to go.

Thanks again!

---

<div class="post-metadata">

**Author:** ![Kevin\_Jones\_505](https://avatars.discourse-cdn.com/v4/letter/k/6de8d8/32.png) [@Kevin\_Jones\_505](https://community.f5.com/u/Kevin_Jones_505)\
**Post date:** [February 22, 2007, 2:01pm UTC](https://community.f5.com/t/telnet-proxy-irule/28303/3 "2007-02-22T14:01:16Z")

</div>

Well, we’ve got our base functionality working with this:

when CLIENT\_ACCEPTED {

TCP::respond “Enter the IP address of destination site.\r\n”

TCP::collect 15

}

when CLIENT\_DATA {

set ip “[TCP::payload]”

node $ip

TCP::release

}

It’s not user friendly; they must enter IP addresses in XXX.XXX.XXX.XXX format (leading zeros when needed) and host names aren’t supported, but it works. Next two steps: add SNAT for return routing and make the IP address input better. If all goes well, then add hostname support.
