Skip to content

Instantly share code, notes, and snippets.

@stanwu
Last active September 27, 2020 15:03
Show Gist options
  • Save stanwu/62fdeee24253cc485aad14a488042b0e to your computer and use it in GitHub Desktop.
Save stanwu/62fdeee24253cc485aad14a488042b0e to your computer and use it in GitHub Desktop.
python telnet example
import getpass
import telnetlib
#
# Please remove line 8, 10 if use for HTTP port 80 only
# class telnetlib.Telnet(host=None, port=0[, timeout])
#
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'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment