3

I am creating a server in python (what it is doing is irrelevant), but I would like it to accept telnet connections and provide a command line interface with line editing capabilities (tabcompletion, emacs/vi-mode, etc) and history per session. I have successfully created the telnet session, disabled line mode and enabled server echo.

My initial thoughts were using readline but the python readline module seems to only work for a single session on stdin; and examining the underlying readline library that seems to be the way it works.

What I would like to do however is to create an instance (call it state if you like) for each client, and as characters (bytes) are received feed to the state. Once a complete line has been generated it would pass it to the server which may parse it.

So my question is if there is a library which handles this kind of thing, even a c-library would be sufficient.

EDIT: To clarify, I've got a fully functional server already, but I want the telnet interface as an add on to reconfigure, get information, etc.

ext
  • 2,593
  • 4
  • 32
  • 45
  • I'm not sure what extra state you could need, if your server is 'fully functional'. Could you explain exactly what you have so far and what you need it to do that it currently cannot? – Kylotan Aug 05 '10 at 10:17
  • I want the server to accept telnet connections which provides a command line interface to access the functionality provided by the server. I've added a listen socket and for each connection it enabled telnet character mode. This is where I am stuck. (As an example, say that I have a webserver which I would like to provide telnet access to change settings and navigate the webroot. This is what I mean with that the server is fully functional, an the telnet part would be an addon. The function of the server is irrelevant.) – ext Aug 05 '10 at 11:25
  • @ext, can you shared how you had got the basic server ready? I need to use something similar but I am not able to achieve the `disabled line mode and enabled server echo` – Tarun Lalwani May 28 '18 at 17:09

3 Answers3

2

It sounds like you've got the TELNET part sorted, and now you want to provide features commonly found in shells like BASH, KSH etc. I've not tried it myself, but have a look as shython: "a versatile shell having features of both bash and python".

Adam
  • 2,110
  • 3
  • 14
  • 17
1

Perhaps the cmd library could be of interest/help?

Amber
  • 507,862
  • 82
  • 626
  • 550
  • I only works for a single session and uses readline. I need something which stores a state for each session so each of them are able to interact independently of each other. – ext Aug 05 '10 at 08:35
  • As the linked page mentions, you can override its input means so that it uses something other than readline. As for sessions, I believe you could create multiple Cmd objects. – Amber Aug 05 '10 at 16:15
0

You need telnetlib http://docs.python.org/library/telnetlib.html?highlight=telnet#module-telnetlib

Yuda Prawira
  • 12,075
  • 10
  • 46
  • 54