Advertisement
Guest User

Untitled

a guest
May 30th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. sys.stderr = open('/dev/null') # Silence silly warnings from paramiko
  4. import paramiko as pm
  5. sys.stderr = sys.__stderr__
  6. import os
  7.  
  8. class AllowAllKeys(pm.MissingHostKeyPolicy):
  9. def missing_host_key(self, client, hostname, key):
  10. return
  11.  
  12. HOST = '192.1.10.1'
  13. USER = 'karn'
  14. PASSWORD = 'mypass'
  15.  
  16. client = pm.SSHClient()
  17. client.load_system_host_keys()
  18. client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
  19. client.set_missing_host_key_policy(AllowAllKeys())
  20. client.connect(HOST, username=USER, password=PASSWORD)
  21.  
  22. channel = client.invoke_shell()
  23. stdin = channel.makefile('wb')
  24. stdout = channel.makefile('rb')
  25.  
  26. stdin.write('''
  27. hostname
  28. uname -a
  29. uptime
  30. who
  31. exit
  32. ''')
  33. print stdout.read()
  34.  
  35. stdout.close()
  36. stdin.close()
  37. client.close()
  38.  
  39. # cat ServerList.txt
  40. Server1
  41. Server2
  42. Server3
  43. ......
  44.  
  45. OR
  46. # cat ServerList2
  47. 192.168.1.1
  48. 192.168.1.2
  49.  
  50. #!/usr/bin/env python
  51. import sys
  52. sys.stderr = open('/dev/null') # Silence silly warnings from paramiko
  53. import paramiko as pm
  54. sys.stderr = sys.__stderr__
  55. import os
  56.  
  57. class AllowAllKeys(pm.MissingHostKeyPolicy):
  58. def missing_host_key(self, client, hostname, key):
  59. return
  60.  
  61. USER = 'karn'
  62. PASSWORD = 'mypass'
  63.  
  64. client = pm.SSHClient()
  65. client.load_system_host_keys()
  66. client.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
  67. client.set_missing_host_key_policy(AllowAllKeys())
  68. with open ('thigo.txt', 'r') as hosts:
  69. for line in hosts:
  70. Serv = line.split()
  71. print Serv
  72. client.connect(Serv, username=USER, password=PASSWORD)
  73. channel = client.invoke_shell()
  74. stdin = channel.makefile('wb')
  75. stdout = channel.makefile('rb')
  76.  
  77. stdin.write('''
  78. hostname
  79. lsb_release -a
  80. exit
  81. ''')
  82.  
  83. print stdout.read()
  84. stdout.close()
  85. stdin.close()
  86.  
  87. Traceback (most recent call last):
  88.  
  89. File "gopygooo.py", line 23, in <module>
  90. client.connect(Serv, username=USER, password=PASSWORD)
  91. File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 277, in connect
  92. socket.getaddrinfo(hostname, port):
  93. TypeError: getaddrinfo() argument 1 must be string or None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement