#!/usr/bin/env python
import threading
import Queue
import time
from ftplib import FTP
ftphostlist = ['ftp.x.org', 'ftp4.FreeBSD.org', 'ftp.ncsa.uiuc.edu',
'ftp.crans.org']
class WorkerThread(threading.Thread):
def __init__(self, queue, tid):
threading.Thread.__init__(self)
self.lock = threading.Lock()
self.queue = queue
self.tid = tid
print "Worker %d Reporting for Service Sir!" % self.tid
def run(self):
while True:
host = None
try:
host = self.queue.get(timeout=1)
#time.sleep(2)
except Queue.Empty:
print "Worker %d exiting..." % self.tid
return
#login to ftp host anonymously and list the dirs
self.lock.acquire()
try:
conn = FTP(host)
conn.login()
print 'Host: ' + host
time.sleep(2)
print host + conn.retrlines('LIST')
except:
print "Error in listing" +host
raise
self.lock.release()
self.queue.task_done()
queue = Queue.Queue()
threads = []
for i in range(1, 5):
t = threading.Thread(target=WorkerThread, args=('Threads -1', 3))
t.start()
print "Creating WorkerThread : %d" %i
worker = WorkerThread(queue, i)
worker.setDaemon(True)
worker.start()
threads.append(worker)
print "WorkerThread %d Created!" %i
time.sleep(.2)
for host in ftphostlist:
queue.put(host)
queue.join()
#wait for all the threads to exit
for item in threads:
item.join
print "Scanning Complete!"
嗨
我对python非常陌生,我正试图按照Pentesteracademy的建议制作FTP连接器。我正在做一个练习,它似乎正确运行了几次,然后我得到一个错误说明
^{pr2}$我不知道我到底哪里出了问题,但我花了好几个小时想弄清楚。抱歉,如果问题很简单,我只是没看到
您的本地模块的名称为
Queue
,正在导入它而不是原始队列:只需重命名您的
/media/sf_Python/Pentest/Queue.py
文件模块对象不可调用可能是由于错误的导入/使用。在
正确的方法是:
或者
^{pr2}$相关问题 更多 >
编程相关推荐