Advertisement
Guest User

Untitled

a guest
May 17th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. servers=["192.168.1.1","192.168.1.2"]
  2.  
  3. class sshClient:
  4. def __init__(self,host):
  5. self.client = paramiko.SSHClient()
  6. self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  7. try:
  8. self.client.connect(host,username="account", password="password")
  9. except paramiko.SSHException:
  10. print "Connection Error"
  11.  
  12. def close(self):
  13. if self.client is not None:
  14. self.client.close()
  15. self.client = None
  16.  
  17. def execute(self, command):
  18. stdin, stdout, stderr = self.client.exec_command(command)
  19. output=''.join(stdout.readlines())
  20. return output
  21.  
  22. class myClass(unittest.TestCase):
  23. def test_test1(self):
  24. self.assertRegexpMatches(_ssh.execute('netstat -nlp | grep -vi unix | grep sshd'),'sshd','sshd not running')
  25.  
  26.  
  27. if __name__ == '__main__':
  28. for server in servers:
  29. _ssh = sshClient(server)
  30. hostname = _ssh.execute('hostname')
  31. hostname = hostname.replace("n","")
  32. print hostname
  33. runner = unitest.TextTestRunner()
  34. unittest.main(testRunner=runner,exit=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement