Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a command history on a telnet client? (up/down arrows)

I have a server that accept telnet connections for management. I miss the command history so I want to make my telnet session support it. My questions:

1) Do I have to implement that on the server side, so the server will send the past commands to the client and then the client can re-execute?

2) Is there anyway to implement this functionality in the telnet client (not messing with the server) ?

If answer is 1) then I need to know how to capture and send the up and down arrow keys on my telnet session without having to press enter.

like image 607
chrisapotek Avatar asked Mar 21 '12 17:03

chrisapotek


People also ask

How does telnet work step by step?

The user connects to the server by using the Telnet protocol, which means entering Telnet into a command prompt by following this syntax: telnet hostname port. The user then executes commands on the server by using specific Telnet commands into the Telnet prompt.

What can I do with telnet commands?

Telnet is a type of client-server protocol that can be used to open a command line on a remote computer, typically a server. Users can utilize this tool to ping a port and find out whether it is open.


2 Answers

This isn't a server issue. Just use rlwrap with your telnet client. It gives you readline with no programming.

$ rlwrap telnet server port

(I actually use nc instead of telnet since it is easier to use and is more robust.)

like image 123
chrisaycock Avatar answered Sep 19 '22 15:09

chrisaycock


use socat:

socat readline,history=$HOME/.telnet_history TCP:host:23
like image 43
salva Avatar answered Sep 20 '22 15:09

salva