python-编写目录扫描工具(单线程版)

用到的模块
requests和sys模块

import requests
import sys

#url = 'http://www.cncpe.cn/'
headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54'
}
url=sys.argv[1]  #传递第一个参数,要扫描的url地址
#dict='ASPX.txt'
dict=sys.argv[2] #传递第二个参数,要扫描的字典文件

with open(dict ,'r') as a:  #打开字典文件,由第二个参数传入,'r'只读模式
    for b in a.readlines():	#把字典循环进b
        b = b.strip()	#.strip()去除换行
        c = requests.get(url=url+b,headers=headers,timeout=30)	#get请求url,由第一个参数传入;在url后面加上b
        if c.status_code != 200: #状态码不为200
            pass
            #print('url:'+c.url+'\t不存在')
        else:
            print(f"网址:{c.url}存在")

利用简单的一段代码实现扫描

你可能感兴趣的:(python,渗透测试工具编写,python,网络,url)