2016-01-23 52 views
1
#!/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!" 

嗨,隊列模塊錯誤

我很新的蟒蛇,並試圖建立FTP連接器通過Pentesteracademy的建議。我工作的這似乎數次正確運行的練習,然後我得到一個錯誤,說明

"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

是這個Python 3? 'python --version' – Will

+0

是否創建了文件'Queue.py'?現在'import Queue'嘗試導入文件'Queue.py',而不是標準的Python模塊。 – furas

回答

4

你當地的模塊命名Queue,它是正在進口的,而不是原來的隊列:

File "ftp_login.py", line 4, in <module> 
    from Queue import * 
    File "/media/sf_Python/Pentest/Queue.py", line 22, in <module> 
     ~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^~ 

只需重命名/media/sf_Python/Pentest/Queue.py文件

+0

非常感謝。這正是問題所在。這個問題在我用名字queue.py保存了一個文件後就開始了。我沒有考慮到這一點。現在很清楚。感謝您的幫助 – IpSp00f3r

+0

@ IpSp00f3r,歡迎您! – soon