2013-10-24 2 views
0

동일한 서버에 도메인을 가져 오는 프로그램을 작성 중이며 웹 디렉토리도 스캔 할 수 있습니다.이 경우 어떻게 queue.put을 쓸 수 있습니까?

#!/usr/bin/env python 
#encoding = utf-8 
import threading 
import urllib,urllib2,httplib 
from urllib2 import Request, urlopen, URLError 

import Queue,sys 
import re 
concurrent = 5 
url = sys.argv[1] 

class Scanner(threading.Thread): 


    def __init__(self, work_q): 
     threading.Thread.__init__(self) 
     self.work_q = work_q 


    def getdomains(self): 
     doreq = Request('http://www.logontube.com/website/'+ url) 
     response = urlopen(doreq) 
     html = response.read() 
     response.close() 
     domains = re.findall('<br><a href=\"(.*?)\" target=\"_blank\"',html) 
     return domains 

    def run(self): 
     alldomains = self.getdomains() 
     pathline = [line.rstrip() for line in open("path.txt")] 


     while True: 
      for aim in alldomains: 
       for path in pathline: 
        path = self.work_q.get() 

        req = Request(aim+path) 
        try: 
         response = urlopen(req) 
        except URLError, e: 
         if hasattr(e, 'reason'): 
          print aim+path,'Not Found' 
         elif hasattr(e,'code'): 
          print aim+path,'Not Found' 
        else: 
         try: 
          logs = open('log.txt',"a+") 
         except(IOError): 
          print "[x] Failed to create log file" 
         print aim+path,"Found" 
         logs.writelines(aim+path+"\n") 
         logs.close() 

def main(): 


    work_q = Queue.Queue() 
    paths = [line.rstrip() for line in open("path.txt")] 
    for i in range(concurrent): 
     t = Scanner(work_q) 
     t.setDaemon(True) 
     t.start() 

    for path in paths: 
     work_q.put(path) 

    work_q.join() 


main()   

이 프로그램은 경로의 루프 만 처리하므로 한 웹 사이트의 검사 결과 만 얻을 수 있습니다. 당신은 내가이 프로그램을 테스트하는 데 도움이하려는 경우, 당신은 당신이 필요로하는

/default.asp 
/index.asp 
/index.htm 
/index.html 
/index.jsp 
/index.php 
/admin.asp 
/admin.php 
/admin.shtml 
/admin.txt 
/admin_admin.asp 
/config.asp 
/inc/ 
/login.asp 
/login.jsp 
/login.php 
/login/ 
/phpinfo.php 
/readme.txt 
/robots.txt 
/test.asp 
/test.html 
/test.txt 
/test.php 
/news/readme.txt 
/addmember/ 

답변

0

(path.txt로 저장) 웹 사이트의 일부 디렉토리를해야 할 수도 있습니다

for path in paths: 
     work_q.put(path) # The program finishes when it puts all the path 

나는이 문제를 발견했습니다 a :

while 1: 
    pass 

또는 스레드가 완료 될 때까지 기다리는 것이 종료됩니다.

무슨 일이 일어나고있는 것은 스레드를 시작하지만 주 스레드를 종료하므로 스레드의 결과를 볼 수 없기 때문입니다.

+0

결과를 볼 수는 있지만 완료되지 않았습니다. 프로그램은 "alldomains에서 목표로"의 루프를 수행하지 않으며, 나는 첫 번째 목표의 결과 만 얻었습니다. – user2876146

+0

글쎄 alldomains의 가치는 무엇입니까'print alldomains' 몇 개의 도메인이 있습니까? – jramirez

+0

urld = sys.argv [1]의 alldomains depende 수량은 동일한 서버에있는 웹 사이트의 수량입니다. – user2876146

관련 문제