Guest User

ke4nhw_python_telnet_automate

a guest
Sep 4th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. Explanation: Any ***** is to obscure sensitive data, such as passwords etc. Any lines with Checkpoint was for me to debug a hangup. The program does work, but I want to see the output from the device so I can confirm the command worked as expected.
  2.  
  3. 1 import getpass
  4. 2 import sys
  5. 3 import telnetlib
  6. 4
  7. 5 HOST = "*******************"
  8. 6 # Another way to do this is: user = raw_input("Enter your user name: ")
  9. 7 user = raw_input("User Name: ")
  10. 8 # print "Checkpoint Line 8 Past UserName Input"
  11. 9 # user = "*********"
  12. 10 # Another way to do this is: password = getpass.getpass()
  13. 11 password = getpass.getpass()
  14. 12 # print "Checkpoint Line 12 Past Password Input"
  15. 13 # password = "***********************"
  16. 14
  17. 15 tn = telnetlib.Telnet(HOST)
  18. 16 # print "Checkpoint Line 16 Past Obj Creation and Connection Opening"
  19. 17 tn.read_until("login: ")
  20. 18 # print "CheckPoint Line 18 Past Read Until Login"
  21. 19 tn.write(user + "\n")
  22. 20 # print "Checkpoint Line 20 Past Write Username and CR"
  23. 21 tn.read_until("Password: ")
  24. 22 # print "Checkpoint Line 22 Past Read Until Password"
  25. 23 tn.write(password + "\n")
  26. 24 # print "Checkpoint Line 24 Past Write Password and CR"
  27. 25 tn.read_until("5308> ")
  28. 26 # print "Checkpoint Line 26 Past Read until 5308"
  29. 27 # tn.write("show net lan dhcp reserved_ip setup\n")
  30. 28 tn.write("security firewall ipv4 enable 20\n")
  31. 29 # print tn.read_all()
  32. 30 # print "Checkpoint Line 28 Past Show Reserved IP Info"
  33. 31 tn.read_until("5308> ")
  34. 32 # print "Checkpoint Line 30 Past Read Until 5308"
  35. 33 tn.write(".exit\n")
  36. 34 # print "Checkpoint Line 32 Past Write Exit"
  37. 35
  38. 36 print tn.read_all()
  39. 37 #print "Checkpoint Line 35 End Of Program"
Add Comment
Please, Sign In to add comment