ʞɔıu
ʞɔıu

Reputation: 48396

How can I run a Python program over telnet?

How can I run a Python program so it outputs its STDOUT and inputs its STDIN to/from a remote telnet client?

All the program does is print out text then wait for raw_input(), repeatedly. I want a remote user to use it without needing shell access. It can be single threaded/single user.

Upvotes: 3

Views: 1115

Answers (4)

tangentstorm
tangentstorm

Reputation: 7297

You can just create a new linux user and set their shell to your script.

Then when they telnet in and enter the username/password, the program runs instead of bash or whatever the default shell is.

Upvotes: 0

McPherrinM
McPherrinM

Reputation: 4594

If you don't need full telnet functionality, you can just use a socket.

Check out the Socket Server module in the standard python library. It'll enable you to easily write a program that'll listen on a port for input/output.

It won't support the proper telnet protocol negotiation, but you might not need that for what you're doing.

Upvotes: 4

Douglas Leeder
Douglas Leeder

Reputation: 53310

Make the Python script into the shell for that user. (Or if that doesn't work, wrap it up in bash script or even a executable).

(You might have to put it in /etc/shells (or equiv.))

Upvotes: 5

Kevin Panko
Kevin Panko

Reputation: 8514

On a Unix system, you can use inetd for this. It will take care of opening the network connection for you, so your program will work as-is.

Upvotes: 10

Related Questions