Guest User

ke4nhw_python_telnet

a guest
Sep 3rd, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. To Explain: Any ******* is to blank out sensitive information, the actual script has the actual information in it.
  2.  
  3. All Checkpoint lines I added to debug a hangup in the program earlier on.
  4.  
  5. This program works but I want to be able to see the router's output with each command issued.
  6.  
  7. 1 import getpass
  8. 2 import sys
  9. 3 import telnetlib
  10. 4
  11. 5 HOST = "*******************"
  12. 6 # Another way to do this is: user = raw_input("Enter your user name: ")
  13. 7 user = raw_input("User Name: ")
  14. 8 # print "Checkpoint Line 8 Past UserName Input"
  15. 9 # user = "*********"
  16. 10 # Another way to do this is: password = getpass.getpass()
  17. 11 password = getpass.getpass()
  18. 12 # print "Checkpoint Line 12 Past Password Input"
  19. 13 # password = "***********************"
  20. 14
  21. 15 tn = telnetlib.Telnet(HOST)
  22. 16 # print "Checkpoint Line 16 Past Obj Creation and Connection Opening"
  23. 17 tn.read_until("login: ")
  24. 18 # print "CheckPoint Line 18 Past Read Until Login"
  25. 19 tn.write(user + "\n")
  26. 20 # print "Checkpoint Line 20 Past Write Username and CR"
  27. 21 tn.read_until("Password: ")
  28. 22 # print "Checkpoint Line 22 Past Read Until Password"
  29. 23 tn.write(password + "\n")
  30. 24 # print "Checkpoint Line 24 Past Write Password and CR"
  31. 25 tn.read_until("5308> ")
  32. 26 # print "Checkpoint Line 26 Past Read until 5308"
  33. 27 # tn.write("show net lan dhcp reserved_ip setup\n")
  34. 28 tn.write("security firewall ipv4 enable 20\n")
  35. 29 # print tn.read_all()
  36. 30 # print "Checkpoint Line 28 Past Show Reserved IP Info"
  37. 31 tn.read_until("5308> ")
  38. 32 # print "Checkpoint Line 30 Past Read Until 5308"
  39. 33 tn.write(".exit\n")
  40. 34 # print "Checkpoint Line 32 Past Write Exit"
  41. 35
  42. 36 print tn.read_all()
  43. 37 #print "Checkpoint Line 35 End Of Program"
Add Comment
Please, Sign In to add comment