How to use telnet in python


SUBMITTED BY: alemotta

DATE: April 8, 2017, 8:17 p.m.

FORMAT: Text only

SIZE: 408 Bytes

HITS: 606

  1. How to use telnet in python
  2. import getpass
  3. import sys
  4. import telnetlib
  5. HOST = "hostname"
  6. user = raw_input("Enter your remote account: ")
  7. password = getpass.getpass()
  8. tn = telnetlib.Telnet(HOST)
  9. tn.read_until("login: ")
  10. tn.write(user + "
  11. ")
  12. if password:
  13. tn.read_until("Password: ")
  14. tn.write(password + "
  15. ")
  16. tn.write("ls
  17. ")
  18. tn.write("exit
  19. ")
  20. print tn.read_all()

comments powered by Disqus