Guest User

Untitled

a guest
Oct 18th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from netmiko import ConnectHandler
  3. from datetime import datetime
  4.  
  5. platform = 'cisco_ios'
  6. username = '#########' # Replace with SSH Username.
  7. password = '#########' # Replace with SSH Password.
  8. i = datetime.now()
  9.  
  10. # Open file with list of switches
  11. f = open ("Switchlist.txt")
  12.  
  13. # Loop and SSH connectivity
  14. for line in f:
  15. print "Trying to connect " + (line) + "\n"
  16. HOST = line.strip()
  17. # print HOST
  18. device = ConnectHandler(device_type=platform, ip=HOST, username=username, password=password)
  19. print "SSH Connection established to :" + (line) + "\n"
  20.  
  21. filename = HOST + '-' + str(i) + '.txt'
  22. device.send_command('terminal length 0')
  23. showrun = device.send_command('show run')
  24. showvlan = device.send_command('show vlan')
  25. showver = device.send_command('show ver')
  26. # Writing IOS configurations to file
  27. print "Copying configurations of " + (line) + "\n"
  28. log_file = open(filename, "a") # in append mode
  29. log_file.write(showrun)
  30. log_file.write("\n")
  31. log_file.write(showvlan)
  32. log_file.write("\n")
  33. log_file.write(showver)
  34. log_file.write("\n")
  35.  
  36. device.disconnect()
  37. print "SSH Connection Closed !" + "\n"
Add Comment
Please, Sign In to add comment