Python 在这种情况下,如何编写queue.put
我正在写一个程序来获取同一服务器中的域,它还可以扫描web目录Python 在这种情况下,如何编写queue.put,python,multithreading,dns,queue,Python,Multithreading,Dns,Queue,我正在写一个程序来获取同一服务器中的域,它还可以扫描web目录 #!/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(threadin
#!/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()
如果你想帮我测试这个程序,你可能需要一些网站目录(另存为path.txt)
您需要一个:
while 1:
pass
或者等待线程完成后退出
发生的情况是,您正在启动线程,但正在终止主线程,因此您永远无法看到线程的结果。我可以看到结果,但它并不完整。程序没有执行“for aim in alldomains”循环,我只得到了第一个aim的结果。那么,alldomains do
print alldomains
的值是多少?alldomains的数量取决于url=sys.argv[1],它是同一服务器中网站的数量。例如,您可以运行它,python WebScaner.py www.facebook.com
/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/
while 1:
pass