Python--简单的目录扫描脚本
生活随笔
收集整理的這篇文章主要介紹了
Python--简单的目录扫描脚本
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author:1stPeakimport requests #導(dǎo)入requests模塊def read_file(filepath): #定義一個(gè)read_file函數(shù),參數(shù)為filepathf = open(filepath,encoding='utf-8').readlines() #打開爆破的字典文件,以行顯示 ,并將返回字典文件賦給f #encoding='utf-8'用來解決:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa3 in position 4680: illreturn f #返回fdef mulubp():mulu = read_file("PHP.txt") #打開目錄爆破字典PHP.txt,賦給mulufor i in mulu: #遍歷mulumulu1 = i.strip("\n") #刪除PHP.txt中的換行,因?yàn)閠xt中沒有換行,但是for循環(huán)執(zhí)行后,會(huì)有換行,也就是新的空白的一行出現(xiàn)mulu2 = mulu1.strip("/") #刪除PHP.txt中每行開始的/ (這個(gè)視情況而定,看你們txt里的字典是怎么設(shè)置的)#print(mulu1) #測(cè)試#print(mulu2) #測(cè)試url="http://www.cztgi.edu.cn/"+str(mulu2)+"" #設(shè)置url#print(url) #測(cè)試response = requests.get(url) #get請(qǐng)求url,值賦給responseresponse2=response.url #返回請(qǐng)求后新的url賦給response2if response.status_code==200 and ".psp" not in response2: #當(dāng)訪問response時(shí)返回的狀態(tài)碼為200并且response2中沒有.psp,執(zhí)行以下代碼,否則,elseprint("[+] "+str(mulu2)+"存在")print("[+] "+str(mulu2)+"存在",file=f) #將print出的數(shù)據(jù)輸送到f文件(爆破結(jié)果.txt)中else:print("[+]:"+str(mulu2)+"不存在")if __name__ == '__main__':filename = '爆破結(jié)果.txt' #創(chuàng)建一個(gè)文件名為爆破.txtwith open(filename, 'w') as f: #以寫入的方式打開爆破.txt,并賦給f #如果filename不存在會(huì)自動(dòng)創(chuàng)建,'w'表示寫數(shù)據(jù),寫之前會(huì)清空文件中的原有數(shù)據(jù)f.write(mulubp()) #調(diào)用mulubp()函數(shù)并將mulubp()函數(shù)運(yùn)行的符合條件值寫入到f中f.close() #關(guān)閉文件的寫入
總結(jié)
以上是生活随笔為你收集整理的Python--简单的目录扫描脚本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安全教案一等奖别摸我
- 下一篇: Python--简单的端口扫描脚本