-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsshclient.py
More file actions
executable file
·34 lines (28 loc) · 844 Bytes
/
sshclient.py
File metadata and controls
executable file
·34 lines (28 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import threading, paramiko
cmd = "someCommand"
outlock = threading.Lock()
def workon(host):
try:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, username='someUser', password='somePass')
stdin, stdout, stderr = ssh.exec_command(cmd)
stdin.write('xy\n')
stdin.flush()
with outlock:
print "Connecting to %s " % host
print stdout.readlines()
except paramiko.AuthenticationException:
print "FAIL " + host
def main():
threads = []
for h in open('hosts.txt'):
h = h.rstrip()
t = threading.Thread(target=workon, args=(h,))
t.start()
threads.append(t)
for t in threads:
t.join()
if __name__ == "__main__":
main()