Last active
September 27, 2020 15:03
-
-
Save stanwu/62fdeee24253cc485aad14a488042b0e to your computer and use it in GitHub Desktop.
python telnet example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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