Guest User

Untitled

a guest
Sep 6th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from paramiko import SSHClient
  4. import paramiko
  5.  
  6. class SSH:
  7. def __init__(self):
  8. self.ssh = SSHClient()
  9. self.ssh.load_system_host_keys()
  10. self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  11. self.ssh.connect(hostname='blhp0032.locaweb.com.br',username='Administrator',password='SenhaServidor')
  12.  
  13. def exec_cmd(self,cmd):
  14. stdin,stdout,stderr = self.ssh.exec_command(cmd)
  15. if stderr.channel.recv_exit_status() != 0:
  16. print stderr.read()
  17. else:
  18. print stdout.read()
  19.  
  20. if __name__ == '__main__':
  21. ssh = SSH()
  22. ssh.exec_cmd("update image force http://firmware.tecnologia.ws/firmware/hpoa485.bin")
  23.  
  24. #!/usr/bin/python
  25.  
  26. from paramiko import SSHClient
  27. import paramiko
  28. import sys
  29.  
  30. class SSH:
  31. def processar(ip):
  32.  
  33. def __init__(self):
  34. self.ssh = SSHClient()
  35. self.ssh.load_system_host_keys()
  36. self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  37. self.ssh.connect(hostname=ip,username='Administrator',password='SenhaServidor')
  38.  
  39. def exec_cmd(self,cmd):
  40. stdin,stdout,stderr = self.ssh.exec_command(cmd)
  41. if stderr.channel.recv_exit_status() != 0:
  42. print stderr.read()
  43. else:
  44. print stdout.read()
  45.  
  46. if __name__ == '__main__':
  47. ssh = SSH()
  48. ssh.exec_cmd("update image force http://firmware.tecnologia.ws/firmware/hpoa485.bin")
  49.  
  50.  
  51. if __name__ == "__main__":
  52. for ip in sys.argv[1:]:
  53. processar(ip)
  54.  
  55. Traceback (most recent call last):
  56. File "update_oa_teste.py", line 24, in <module>
  57. ssh.exec_cmd("update image force http://firmware.tecnologia.ws/firmware/hpoa485.bin")
  58. AttributeError: SSH instance has no attribute 'exec_cmd'
Add Comment
Please, Sign In to add comment