Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. import paramiko as pm
  4. import os
  5. sys.stderr = open('/dev/null') # Silence silly warnings from paramiko
  6. sys.stderr = sys.__stderr__
  7.  
  8.  
  9. class AllowAllKeys(pm.MissingHostKeyPolicy):
  10. def missing_host_key(self, client, hostname, key):
  11. return
  12. with open('host.txt') as f:
  13. for HOST in f:
  14. USER = 'test'
  15. PASSWORD = '123'
  16.  
  17. client = pm.SSHClient()
  18. client.load_system_host_keys()
  19. client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
  20. client.set_missing_host_key_policy(AllowAllKeys())
  21. client.connect(HOST, username=USER, password=PASSWORD)
  22.  
  23. channel = client.invoke_shell()
  24. stdin = channel.makefile('wb')
  25. stdout = channel.makefile('rb')
  26.  
  27. stdin.write('''
  28. hostname
  29. lsb_release -a
  30. exit
  31. ''')
  32. print stdout.read()
  33.  
  34. stdout.close()
  35. stdin.close()
  36. client.close()
  37.  
  38. Traceback (most recent call last):
  39. File "Remoteconnect2.py", line 21, in <module>
  40. client.connect( HST, username=USER, password=PASSWORD )
  41. File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 277, in connect
  42. socket.getaddrinfo(hostname, port):
  43. socket.gaierror: [Errno -2] Name or service not known
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement