Guest User

Untitled

a guest
Nov 10th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import paramiko
  2. import sys
  3. import time
  4.  
  5.  
  6. USER = "root"
  7. PASS = "cisco"
  8. HOST = ["10.10.10.10","11.11.11.11","12.12.12.12"]
  9. i=0
  10. while i <len(HOST)
  11. def fn():
  12. client1=paramiko.SSHClient()
  13. #Add missing client key
  14. client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  15. #connect to switch
  16. client1.connect(HOST,username=USER,password=PASS)
  17. print "SSH connection to %s established" %HOST
  18.  
  19. show run | redirect tftp://10.10.10.20/HOST.cfg
  20. print "Configuration has been backed up"for %HOST
  21. i+1
  22.  
  23. for h in HOST:
  24. client = paramiko.SSHClient()
  25. #Add missing client key
  26. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  27. #connect to switch
  28. client.connect(h, username = USER, password = PASS)
  29. print("SSH connection to {0} established".format(h))
  30. command = "show run | redirect tftp://10.10.10.20/{0}.cfg".format(h)
  31. (stdin, stdout, stderr) = client.exec_command(command)
  32. for line in stdout.readlines():
  33. print(line)
  34. client.close()
  35. print("Configuration has been backed up for {0}".format(h))
Add Comment
Please, Sign In to add comment