/
ftpscanner_multithread.py
58 lines (43 loc) · 1.38 KB
/
ftpscanner_multithread.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
#!/usr/bin/python
import ftplib
import threading
import Queue
class ftpscan(threading.Thread):
def __init__(self,queue,lock):
threading.Thread.__init__(self)
self.queue = queue
self.lock = lock
def run(self):
while True:
self.lock.acquire()
self.queue.get()
#ftpclient = ftplib.FTP(ftpserver.strip())
self.queue.task_done()
self.lock.release()
def main():
queue = Queue.Queue()
lock = threading.Lock()
ftplist = open("ftpsites","r")
counter = 1
for tid in range(5):
print "Creating FTPSCAN Thread: %d"%tid
ftpscan_Thread = ftpscan(queue,lock)
ftpscan_Thread.setDaemon(True)
ftpscan_Thread.start()
print "FTPSCAN Thread %d created"%tid
for ftpserver in ftplist.readlines():
ftp = ftplib.FTP(ftpserver.strip())
queue.put(ftpserver.strip())
print "------------------------------------------------------------------------------"
print "<%d> FTP Server: "%counter + ftpserver.strip()
print "------------------------------------------------------------------------------"
ftp.login()
ftp.retrlines('LIST')
ftp.quit()
queue.join()
print "------------------------------------------------------------------------------"
print "Listing directory at FTP Server: " + ftpserver.strip() + " finished"
print "------------------------------------------------------------------------------" + "\n"
counter += 1
if __name__ == main():
main()