Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import time
  2. import telnetlib
  3. from my_ccie_routers import PE1, PE2, P1, P2, P3, P4
  4.  
  5.  
  6. def open_telnet_conn(ip):
  7. global username
  8. global password
  9. telnet_port = 23
  10. telnet_timout = 5
  11. read_timout = 5
  12. #Logging into device
  13. connection = telnetlib.Telnet(ip, telnet_port, telnet_timout)
  14. output = connection.read_until("Username:", read_timout)
  15. connection.write(username + "\n")
  16. output = connection.read_until("Password:", read_timout)
  17. connection.write(password + "\n")
  18. time.sleep(1)
  19. # output = connection.read_until(">", read_timout)
  20. # connection.write('enable' + "\n")
  21. # time.sleep(1)
  22. # output = connection.read_until("Password:", read_timout)
  23. # connection.write(password + "\n")
  24. # time.sleep(1)
  25. #Setting terminal length for entire output - no pagination
  26. connection.write("terminal length 0\n")
  27. #time.sleep(1)
  28. #Entering global config mode
  29. connection.write("\n")
  30. connection.write("configure terminal\n")
  31. time.sleep(1)
  32. global router_hostname
  33. print "Python successfully entered the configuration mode of " + ' ' + router_hostname
  34. print "=================================================================================="
  35. connection.write("\n")
  36. global Configurations_to_be_pushed
  37. connection.write(Configurations_to_be_pushed)
  38. time.sleep(1)
  39. #to see the command line of the routers while configuring them
  40. output = connection.read_very_eager()
  41. print output
  42.  
  43.  
  44. username = 'ccie'
  45. password = 'ccie'
  46. routers = [P1, P2, P3, P4, PE1, PE2]
  47.  
  48. for router in routers:
  49.  
  50. router_ip = router['ip']
  51. router_hostname = router['hostname']
  52. Configurations_to_be_pushed = 'username python password python'
  53. open_telnet_conn(router_ip)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement