-
Notifications
You must be signed in to change notification settings - Fork 10
/
rscan.py
executable file
·78 lines (60 loc) · 1.6 KB
/
rscan.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/python
import init
import threading
import time
import sys
import paramiko
username = init.username
password = init.newpassword
ips = init.ips
scriptpath = "/work/do"
def usage():
out ( "Usage: %s port" % sys.argv[0])
exit()
def out(con):
print con
def worker(ip, lock, script,i):
# execute the addhash script and print the result
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,22,username,password,timeout=5)
lock.acquire()
#out ("\n################################ %s ################################## " % ip )
cmd = script
lock.release()
#stdin,stdout,stderr = ssh.exec_command(cmd)
s = ssh.invoke_shell()
time.sleep(1)
welcome = s.recv(2048)
cdcmd = "cd %s\n" % scriptpath
s.send(cdcmd)
time.sleep(0.1)
s.send(cmd + '\n')
buf = ""
while not buf.endswith('# '):
time.sleep(1)
lock.acquire()
recv = s.recv(4096)
sys.stdout.write("\n%s\n\t%s" % (ip, recv))
lock.release()
buf += recv
out('\n')
def main():
global scriptpath
port = sys.argv[1]
cnt = len(ips)
lock = threading.Lock()
ts = []
for i in range(cnt):
scancmd = "python worker_scanport.py %s %s %s " % (port,cnt,i)
t = threading.Thread(target=worker, args=(ips[i], lock, scancmd, i))
ts.append(t)
for t in ts:
t.setDaemon(True)
t.start()
for t in ts:
t.join()
if __name__ == '__main__':
if len(sys.argv) not in [2,3]:
usage()
main()