Advertisement
Guest User

Untitled

a guest
Sep 19th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1.  
  2. #!/usr/bin/env python
  3.  
  4. #CREATED BY ELNUR
  5.  
  6. import paramiko
  7. import datetime
  8. import time
  9.  
  10. hostnames_list = {
  11.     "CISCO-3B" : "10.0.0.2",
  12.     "CISCO-1B" : "10.0.0.3",
  13.     "FLOOR-2A" : "10.0.0.4",
  14.     "CISCO-1A" : "10.0.0.5",
  15.     "CISCO-1C" : "10.0.0.6",
  16.     "FLOOR-0A" : "10.0.0.7",
  17.     "CISCO-3A" : "10.0.0.8",
  18.     "ASB4" : "10.0.0.9",
  19.     "ASB-3" : "10.0.0.10",
  20.     "CISCO-2B" : "10.0.0.11",
  21.     "CISCO-4B" : "10.0.0.12",
  22.     "PAVILION-5" : "10.0.0.13",
  23.     "Asb_6" : "10.0.0.14",
  24.     }
  25. port = 22
  26. username = "admin"
  27. password = "azsxdcfvgbhn*1"
  28.  
  29. def RebootAccessPoints():
  30.     if __name__ == "__main__":
  31.         ssh = paramiko.SSHClient() #Importing SSH client
  32.         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # add finger print to the known hosts
  33.         for key,value in hostnames_list.iteritems():
  34.             try:
  35.                 ssh.connect(value,port,username,password)
  36.                 stdin,stdout,stderr = ssh.exec_command("reboot") # which command do you want execute
  37.                 print str(datetime.datetime.now()) + " %s rebooted successfully!" % key
  38.             except paramiko.ssh_exception.NoValidConnectionsError: # executed if there is any problem with connection
  39.                 print str(datetime.datetime.now()) + " There is connection error with %s" % key
  40.             ssh.close()
  41.  
  42.  
  43.  
  44. RebootAccessPoints()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement