工具原理:

通过读取字典获取内容,拼接url执行get http请求获取

响应状态码,根据状态码判断目录文件资源是否存在

1

2

思路:

工具命令行参数获取

1

字典读取

1

多线程访问

1

状态码获得判断输出结果

1

工具初始化

定义一个banner信息函数 def banner()

用于介绍工具与名称

1

2

def banner():

print("*" * 51)

print("*" * 2 + " " * 17 + "DirBurte v1.0" + ' ' * 17 + "*" * 2)

print('*' * 51)

print("This tool just debvlop for education!")

1

2

3

4

5

使用方法信息函数:

def usage():使用方法

1. url

2. thread

3. dictionary

1

2

3

4

def usage():

print("This is the tool's usage")

print("python Dirbrute.py -r u url -t thread -d dictionary")

1

2

3

参数获取

模块介绍

1

sys sys.argv获取python命令行执行的数据,sys.argv[0]

1

getopt python自带的解析命令行参数模块

1

参数获得

opts,args = getopt.getopt(sys.argv[1:],"u:t:d")

每一个参数都有一个值,传递给opts,输出opts

可以看到是一个列表类型

1

2

3

根据使用方法,可知len(sys.argv)等于7才能执行

将参数获得的内容封装到start函数中

1

2

def start():

if len(sys.argv) == 7:

opts,argv = 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:

print("error Argument")

sys.exit()

字典文件的读取

python字典文件读取

with open(filename,mode)as f:

f.readlines()

这里使用with open() as f的好处在于

如果打开一个字典文件或者其他文件,那么

这个文件流只有再调用close()的时候才会关闭

1

2

3

不调用的话,文件流会一直处于打开状态

即是占用资源又占用文件,使得无法进行其他操作

例如删除等

多线程思路

一个线程读取固定数目的字典文件内容

制作多线程使用的字典列表,存储都是以列表格式

def multi_scan(url,threads,dic):

with open("dir",'r') as f:

dic_list = f.readlines()#读取字典

result_list = []#用来存放字典列表

threads_list = []#生成一个空的线程列表,后面用来追加子线程

##第二步确认字典行数

if len(dic_list) % int(threads) == 0:

threads_read_line_num = len(dic_list) / int(threads)

else:

threads_read_line_num = math.ceil(len(dic_list) / int(threads))

i = 0

temp_list = []

for line in dic_list:

i += 1

if i % threads_read_line_num == 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()

线程列表

读取字典列表中的内容

扫描scan函数

def scan(url,dic):

for line in dic:

r = requests.get(url+'/'+line)

if r.status_code == 200:

print(r.url+':'+str(r.status_code))

else:

pass

完整代码为

#!/usr/bin/python3

import getopt

import sys

import math

import threading

import requests

def banner():

print("*"*51)

print("*"*2+" "*17+"DirBurte v1.0"+' '*17 +"*"*2)

print('*'*51)

print("This tool just debvlop for education!")

def usage():

print("This is the tool's usage")

print("python Dirbrute.py -r u url -t thread -d dictionary")

def start():

if len(sys.argv) == 7:

opts,argv = 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:

print("error Argument")

sys.exit()

def multi_scan(url,threads,dic):

with open("dir",'r') as f:

dic_list = f.readlines()

result_list = []

threads_list = []

if len(dic_list) % int(threads) == 0:

threads_read_line_num = len(dic_list) / int(threads)

else:

threads_read_line_num = math.ceil(len(dic_list) / int(threads))

i = 0

temp_list = []

for line in dic_list:

i += 1

if i % threads_read_line_num == 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()

def scan(url,dic):

for line in dic:

r = requests.get(url+'/'+line)

if r.status_code == 200:

print(r.url+':'+str(r.status_code))

else:

pass

start()

python list除以_扫描器篇(三)之python编写基于字典的网站目录探测脚本相关推荐

  1. python 追加到字典_扫描器篇(三)之python编写基于字典的网站目录探测脚本

    工具原理: 通过读取字典获取内容,拼接url执行get http请求获取 响应状态码,根据状态码判断目录文件资源是否存在 1 2 思路: 工具命令行参数获取 1 字典读取 1 多线程访问 1 状态码获 ...

  2. 判断端口是否能用_扫描器篇(八)之python+scapy构造TCP协议包扫描主机端口

    TCP协议端口扫描 要使用TCP协议去完成端口扫描,肯定是需要了解TCP协议通信过程和原理才能完成的 TCP协议的特点 1 面向连接的:使用TCP协议通信的双方必须先建立连接,然后才能开始数据的读写, ...

  3. Python之路【第二篇】:Python基础(一)

    Python之路[第二篇]:Python基础(一) 入门知识拾遗 一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 1 2 3 if 1==1:     name ...

  4. Python之路【第一篇】:Python简介和入门

    Python之路[第一篇]:Python简介和入门 Python简介 Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗 ...

  5. Python学习【第1篇】:Python简介以及入门

    python第一篇-------python介绍 一.python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,Guido开始写Python语 ...

  6. 云计算Python自动化运维开发实战 三、python文件类型

    为什么80%的码农都做不了架构师?>>>    云计算Python自动化运维开发实战 三.python文件类型 导语: python常用的有3种文件类型 1. 源代码     py ...

  7. python自动化从零开始_从零开始的自动化测试框架——Python篇

    随着软件测试领域对于技术要求越来越清晰,到现在测试人员在市场上的岗位需求也变得越来越复杂.极大部分的企业都开始对自动化测试岗位有了更多的需要.自然而然,自动化测试技术开始成为了下一个被玩烂的技术点.网 ...

  8. 怎么用python自制计算公式_手把手教你用python制作简易计算器,能够记录你使用的情况...

    话不多说,首先先看效果图,它能够记录你在使用过程中的历史,方便你查看是否有错: 接下来就仔细分析一下是如何制作的: 简易计算器 第一步:导入资源库 在过程中使用到了tkinter这个资源库,win+R ...

  9. python做运动控制_第一课:用Python操控小龟小车运动

    欢迎来到小龟的课堂,今天我们讲如何用小龟小车的车载Python控制小车运动. 如果小伙伴还不会使用小龟小车的Python编辑器的话,可以阅读这篇教程<如何使用小龟小车的Python编辑器> ...

最新文章

  1. 报告 | 野蛮数据时代,企业和从业者如何应对变革焦虑?
  2. mysql2008无法启动_SQL Server 2008突然无法正常启动
  3. Linux 应用层的时间编程【转】
  4. consul配置参数大全、详解、总结
  5. (pytorch-深度学习)实现稠密连接网络(DenseNet)
  6. Ubuntu——系统扩容(加硬盘)的学习笔记
  7. StarTeam 使用小记
  8. { parser: “babylon“ } is deprecated; we now treat it as { parser: “babel“ }.
  9. 数学建模(零)入门统领
  10. 什么是java实例化?举例说明
  11. Linux命令之udhcpc,自动获取IP地址
  12. 合工大离散数学实验 油管实验
  13. 科技巨头们以 A 取名的时尚潮流
  14. 电脑重装系统苹果笔记本开不了机的解决措施有哪些
  15. 用VBA检查Word文档中是否存在位于行首的脚注引用,如存在则通过调整字符间距使其移动到非行首的位置
  16. 在单面打印机上使用WPS实现手工双面打印
  17. Chrome 安装插件与使用技巧
  18. 《脑机接口导论》学习笔记 3.记录大脑的信号和刺激大脑
  19. 基于ssm的养老智慧服务平台毕业设计源码071526
  20. 3D游戏建模入门基础:3dmax常用功能详解

热门文章

  1. 每日一皮:进来说说昨天你是怎么过的?
  2. @Async的使用、原理及使用时可能导致的问题
  3. 你想学习Java ?资源都在这里了
  4. Spring Cloud Config对特殊字符加密的处理
  5. Spring Cloud构建微服务架构:分布式服务跟踪(收集原理)【Dalston版】
  6. mysql简单概述_MySQL入门很简单: 1 数据库概述
  7. 辽宁师范大学计算机科学与技术在哪个校区,辽宁师范大学有几个校区及校区地址 哪个校区最好...
  8. SCRFD is not in the models registry
  9. python文件排序
  10. No module named 'dlframework.common.utils.local'