#!/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连接器。我正在进行一项运动,似乎运行了几次,然后我得到一个错误说明
"File "ftp_login.py", line 4, in <module>
from Queue import *
File "/media/sf_Python/Pentest/Queue.py", line 22, in <module>
queue = Queue.Queue()
TypeError: 'module' object is not callable"
我不确定我错在哪里,但我花了不少时间试图解决这个问题。对不起,如果问题很简单,我只是没有看到它
答案 0 :(得分:4)
您的本地模块名称为SELECT tf.filename FROM tempfile
,而且正在导入而不是原始队列:
Queue
只需重命名您的File "ftp_login.py", line 4, in <module>
from Queue import *
File "/media/sf_Python/Pentest/Queue.py", line 22, in <module>
~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^~
文件
答案 1 :(得分:0)
模块对象不可调用,可能是由于导入/使用错误。
正确的方法是:
from Queue import Queue
q = Queue()
或
import Queue
q = Queue.Queue()