• 目录遍历学习



    #
    conding:utf-8 import requests import sys #加载字典文件 #使用with .. as ..会自动关闭文件流;使用f = open(“filename.txt”,”r”) 需要close关闭文件流。 #每次读取1行 f.readline() #一次读取完 f.readlines() #读取X个字节 f.read(X) with open('big.txt','r',encoding='UTF-8') as readfile: for dirs in readfile.readlines(): #生成对应url url ="http://www.baidu.com/"+dirs.strip('\n') resp = requests.get(url) strlen=len(resp.text) #将扫描结果输出 print(url+'---'+str(resp.status_code)) #判断特殊状态码,将对应url保存到文件之中 if resp.status_code ==200 or resp.status_code==403 or resp.status_code==301 or resp.status_code==500: with open('write.txt','a',encoding='UTF-8') as writefile: writefile.write(url+'---'+str(resp.status_code))
    import requests
    import sys
    
    url = sys.argv[1]     
    with open("dir.txt","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 + "  存在")
    #conding:utf-8
    import math,threading,sys,getopt,requests
    #介绍
    def banner():
        print()
        print("*" * 2 + " " * 17 + "DIR" + " " * 17 + "*" * 2)
        print()
    def usage():
        print()
        print("python main.py -u url -t thread -d dictionary")
        print()
    #多线程
    def multi_scan(url,threads,dic):
        result_list = [] #存放字典的最终列表
        with open("/Users/bingtanghulu/Desktop/dic.txt","r")as f:
            dic_list = f.readlines()
            lenth = len(dic_list)
            #确定一个线程读取几行字典的内容,Math.ceil()方法返回大于或等于给定浮点数的最小整数。
            thread_read_line_num = math.ceil(len(dic_list) / int(threads))
            i = 0
            temp_list = [] #临时列表
            for line in dic_list:
                i = i + 1
                if i % thread_read_line_num == 0:  # 如果够一个线程取得数量了
                    temp_list.append(line.strip())
                    result_list.append(temp_list)  # 将当前线程创建的临时列表  存放到最终空列表中
                    temp_list = []
                elif i == lenth:  # 防止不够整除,少了最后一个数组。
                    temp_list.append(line.strip())  
                    result_list.append(temp_list)
                else:
                    temp_list.append(line.strip())  # 放一个数据到临时列表
        # print(result_list)               #打印输出最终列表
        threads_list = []  # 定义一个空的多线程列表
        # 制作一个多线程列表
        for i in result_list:
            threads_list.append(threading.Thread(target=scan, args=(url, i)))  # url由命令行传入
        # 启动多线程
        for t in threads_list:
            t.start()
    #定义一个目录扫描函数
    def scan(url,dic):
        headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"}
        for line in dic:
            r = requests.get(url+'/'+line,headers=headers)
            if r.status_code == 200:
                print(r.url + " : " + str(r.status_code))
    #定义获取命令行参数的函数,也是程数开始的地方
    def start():
        banner()
        if len(sys.argv)  == 7:
            opts,args = getopt.getopt(sys.argv[1:],"u:t:d:")        #从命令行获取参数
            for k,v in opts:
                #print(k,v)
                if k == '-u':               #这个  “ - ”不要忘了
                    url = v
                elif k == '-t':
                    threads = v
                elif k == '-d':
                    dic = v
                else:
                    print("传输的参数有误")
                    usage()
                    sys.exit()  # 结束当前程序
    
            multi_scan(url,threads,dic)     #将获取到的参数传入多线程函数,并执行。
        else:
            print("传输的参数有误")
            usage()
            sys.exit()              #结束当前程序
    
    if __name__ =="__main__":
        start()
  • 相关阅读:
    计蒜客 跳跃游戏2
    计蒜客 跳跃游戏
    2018 计蒜之道-初赛 第一场 A-百度无人车
    poj 3625 (最小生成树算法)
    poj 3623(贪心)
    poj2386(dfs搜索水题)
    poj 2761 主席树的应用(查询区间第k小值)
    POJ 2456 编程技巧之------二分查找思想的巧妙应用
    POJ 1995(有关快速幂运算的一道水题)
    1441:【例题2】生日蛋糕
  • 原文地址:https://www.cnblogs.com/bingtang123/p/15919841.html
Copyright © 2020-2023  润新知