第一个
地址:
http
://www
.miaosj
.cn
/
思路:
"""
通过分析判断网页返回的状态码来表明目录是否存在
1.访问网页
2.查看状态码
3.判断网页是否存在
"""
代码:
import requests
url
= "http://www.miaosj.cn/"
headers
= {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
}
print("开始( ̄_, ̄ )执行......")
def file(file1
):
f
= open(file1
,encoding
='utf-8').readlines
()
return f
def run():
run
= file("2.txt")
for i
in run
:
cf
= i
.strip
("\n")
URL
= url
+ str(cf
)
response
= requests
.get
(URL
,headers
=headers
)
if response
.status_code
== 200:
print("[+]" + str(cf
) + "存在")
print("[+]" + str(cf
) + "存在",file=f
)
else:
print("[+]" + str(cf
) + "不存在")
return ""
with open("1.txt",'w') as f
:
f
.write
(run
())
f
.close
()
第二个
import requests
import sys
url
= sys
.argv
[1]
dic
= sys
.argv
[2]
with open(dic
,"r") as f
:
for line
in f
.readlines
():
line
= line
.strip
()
r
= requests
.get
(url
+ line
)
if r
.status_code
== 200:
print("url:" + r
.url
)
第三个多线程
import getopt
import sys
import math
import threading
import requests
def banner():
print("*"*50)
print("奥里给 v1.0")
print("*" * 50)
print("this is the tool's usage")
print("python 奥里给 v1.0 -u url -t thread -d dictionary")
def start():
if len(sys
.argv
) == 7:
opts
, args
= getopt
.getopt
(sys
.argv
[1:], "u:t:d:")
for k
,v
in opts
:
if k
== "-u":
url
= v
elif k
== "-t":
threads
= v
elif k
== "-d":
dic
= v
multi_scan
(url
,threads
,dic
)
else:
banner
()
sys
.exit
()
def multi_scan(url
,threads
,dic
):
result_list
= []
threads_list
= []
with open(dic
,"r") as f
:
dic_list
= f
.readlines
()
if len(dic_list
) % int(threads
) == 0:
result
= len(dic_list
) / int(threads
)
else:
result
= math
.ceil
(len(dic_list
) / int(threads
))
print(result
)
i
= 0
temp_list
= []
for line
in dic_list
:
i
= i
+1
if i
% result
== 0:
temp_list
.append
(line
.strip
())
result_list
.append
(temp_list
)
temp_list
= []
else:
temp_list
.append
(line
.strip
())
for i
in result_list
:
threads_list
.append
(threading
.Thread
(target
=scan
,args
=(url
,i
)))
for t
in threads_list
:
t
.start
()
print(result_list
)
def scan(url
,dic
):
for line
in dic
:
r
= requests
.get
(url
+ '/' + line
)
if r
.status_code
== 200:
print(r
.url
+ " "*15 + str(r
.status_code
))
start
()
转载请注明原文地址:https://blackberry.8miu.com/read-33541.html