Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import paramiko
  5. import datetime
  6. import time
  7.  
  8. hostnames_list = {
  9.     "XXXXX" : "10.0.0.2",
  10.     "XXXXX" : "10.0.0.3",
  11.     "XXXXX" : "10.0.0.4",
  12.     "XXXXX" : "10.0.0.5",
  13.     "XXXXX" : "10.0.0.6",
  14.     "XXXXX" : "10.0.0.7",
  15.     }
  16. port = 22
  17. username = "admin"
  18. password = "XXXXXXXX"
  19.  
  20. def RebootAccessPoints():
  21.     if __name__ == "__main__":
  22.         ssh = paramiko.SSHClient() #Importing SSH client
  23.         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # add finger print to the known hosts
  24.         for key,value in hostnames_list.iteritems():
  25.             try:
  26.                 ssh.connect(value,port,username,password)
  27.                 stdin,stdout,stderr = ssh.exec_command("reboot") # which command do you want execute
  28.                 print str(datetime.datetime.now()) + " %s rebooted successfully!" % key
  29.             except paramiko.ssh_exception.NoValidConnectionsError: # executed if there is any problem with connection
  30.                 print str(datetime.datetime.now()) + " There is connection error with %s" % key
  31.             ssh.close()
  32.  
  33.  
  34.  
  35. RebootAccessPoints()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement