简体   繁体   中英

How to setup telnet server in python

How can I build a telnet server in python? What tools should I use? I've seen a lot of code on the internet but nothing worked. It needs to run a python file as a shell with no login prompt. How can I do that?

The telnetlib module provides a Telnet class that implements the Telnet protocol.

A simple example illustrating typical use:

import getpass
import telnetlib

HOST = "localhost"
user = input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

tn.write(b"ls\n")
tn.write(b"exit\n")

print(tn.read_all().decode('ascii'))

More details:

https://docs.python.org/3/library/telnetlib.html

To install the library, type this command:

pip install telnetlib3

Try this module.

You can install it using pip.

pip install telnetserver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM