欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python編寫合并字典并實(shí)現(xiàn)敏感目錄的小腳本

 更新時(shí)間:2019年02月26日 14:27:36   作者:不成大佬不改名  
這篇文章主要介紹了Python編寫合并字典并實(shí)現(xiàn)敏感目錄的小腳本,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

0x00 起因

接觸網(wǎng)安快一年了,愛收集一些字典啊敏感目錄文件啊什么的。收集多了難免有重復(fù),并且有的也需要合并使用方便。自己就寫了一個(gè)小小的腳步用來完成這個(gè)目的。

0x01 代碼

第一次發(fā)表文章,希望大家多提意見。抱拳了!

代碼我就貼出來了

import osimport time
import argparse
import optparse

def Time(n,p):
  pat_time = p-n
  minute = pat_time/60
  hour = minute/60
  print(int(hour),'小時(shí)',int(minute%60),'分鐘',int(pat_time%60),'秒')

def __O__(path): #遍歷目錄,包括目錄里的子目錄
  f = os.listdir(path) #查看路徑下所有文件及目錄
  D = open('D.txt','w')
  F = open('F.txt','w')
  for i in f:
    fil = os.path.join(path,i) #dir是絕對(duì)路徑
    if os.path.isdir(fil): #如果fil是目錄加入到D里
      D.write(fil)
      __O__(fil) #繼續(xù)執(zhí)行當(dāng)前函數(shù)
    if os.path.isfile(fil): #如果是文件,加入到F里
      F.write(fil)
  D.close()
  F.close()


def type_txt(file,path): #傳入路徑,文件名(列表)
  try:
    n = time.time()
    print(' 準(zhǔn)備執(zhí)行!')
    path_list = []  #存放需要打開的文件
    di = {}
    date_list = []
    dict_li = ['new_php.txt', 'new_asp.txt', 'new_aspx.txt', 'new_jsp.txt', 'new_dir.txt', 'new_mdb.txt',] #合并的字典列表
    for i in dict_li:
      di = []
    for h in file:               #合并給的路徑及文件名
      fn = os.path.join(path, h)
      path_list.append(fn)
    for j in path_list: #循環(huán)需要打開的文件列表
      print(' 文件為:',j)
      with open(j, 'r') as f:
        date = f.readlines()

        print(' -t 當(dāng)前執(zhí)行文件為: ' + j,'數(shù)量:',len(date))
        for i in date:     #讀取每一行
          af, aq = os.path.splitext(i)        #分裂成路徑及后綴名
          aq = aq.lower()
          if i != '\n':               #如果沒有換行符會(huì)加上
            if '\n' not in i:
              i = i + '\n'
              aq+='\n'
            if aq == '.php\n' and i not in di['new_php.txt']:            #判讀后綴名并通過后綴名放到相應(yīng)的字典中,同時(shí)判讀字典對(duì)應(yīng)的文件列表中是否存在,如果是False則加入進(jìn)去
              di['new_php.txt'].append(i)
            elif aq == '.asp\n' and i not in di['new_asp.txt']:
              di['new_asp.txt'].append(i)
            elif aq == '.aspx\n' and i not in di['new_aspx.txt']:
              di['new_aspx.txt'].append(i)
            elif aq == '.jsp\n' and i not in di['new_jsp.txt'] :
              di['new_jsp.txt'].append(i)
            elif (aq == ('.ini\n' or '.xml\n' or '.cgi\n' or '.log\n' or '.db\n' or '.mdb\n' or '.sql\n' or '.xml\n' or '.htm\n' or '.html\n' or '.bak\n' or '.dbf\n' or '.zip\n' or '.rb\n' or '.js\n' or '.css\n' or '.html?\n')) and i not in di['new_mdb.txt']:
              di['new_mdb.txt'].append(i)
            elif i not in di['new_dir.txt'] :
              di['new_dir.txt'].append(i)
        f.close()
  except (UnicodeDecodeError) as e:
      print("字典文件中有錯(cuò)誤請(qǐng)檢查是否是字典",e)
  di1,fi = os.path.split(path)
  print(' 分類完畢......準(zhǔn)備寫入')
  for key in di:                 #寫入到文件中
    o = open(key,'w')
    for i in di[key]:
      o.write(i)
  Time(n, time.time())

def dir_txt(path):                                   #傳進(jìn)去路徑,返回來的是路徑下的后綴為txt的文件。如果沒有則是當(dāng)前路徑。
  dir_txt = []
  a = os.listdir(path)
  for i in a:
    dd, ff = os.path.splitext(i)
    if ff == '.txt':
      dir_txt.append(i)
  return dir_txt




def password(file,path):
  try:
    path_list = []
    password_list = []
    for i in file:
      pathl = os.path.join(path,i)
      path_list.append(pathl)
    print(" 開始去除重復(fù).....")
    for i in path_list:      #重復(fù)每一個(gè)給定的密碼文件
      F = open(i,'r')
      txt = F.readlines()
      F.close
      for j in txt:    #讀取每一個(gè)密碼文件,并且判讀是否存在于password_list列表,如不存在則放進(jìn)列表
        if '\n' not in j:
          j+='\n'
        if j not in password_list:
          password_list.append(j)
    print(" 完成,并且準(zhǔn)備寫入。")
    file = open('Password.txt','w')    #打開即將寫入的Password.txt,把passowrd_list列表數(shù)據(jù)全部寫入進(jìn)去
    for i in password_list:
      file.write(i)
    file.close
    print(" 運(yùn)行完畢。")
  except :
    print(" 請(qǐng)檢查文件是否存在,路徑是否正確。")

def Optparse():
  try:
    parser = argparse.ArgumentParser(
    """把字典分類:new_php.txt,new_asp.txt,new_aspx.txt,new_jsp.txt,new_mdb.txt,new_dir.
    
    
    
                     -t -path C:\\x\\x\*   
                     -t -path C:\\x\\x -file xxx.txt,xx.txt   """)

    group = parser.add_mutually_exclusive_group()
    group.add_argument('-p',action='store_true',help='密碼合并')           #-p 和-t參數(shù)是互相排斥的,并不能一起使用。
    group.add_argument('-t',action='store_true',help='后臺(tái)目錄字典合并',)
    parser.add_argument('-file', type=str, help='輸入的文件',required=False)
    parser.add_argument('-path',type=str,help='你所指定的目錄',required=False)
    args = parser.parse_args()

    if args.t:      #判讀t是否真
      if args.file == None:
        path,file = os.path.split(args.path)
        dir__txt = dir_txt(path)
        type_txt(dir__txt,path)
      elif args.file != None:
        list_file = args.file.split(',')
        type_txt(list_file,args.path)
    elif args.p:    #判讀p是否真
      if args.file == None:
        path, file = os.path.split(args.path)
        dir__txt = dir_txt(path)
        password(dir__txt,path)
      elif args.file != None:
        list_file = args.file.split(',')
        password(list_file,args.path)
    else:
      print(" 錯(cuò)誤請(qǐng)檢查輸入。")
  except (KeyboardInterrupt):
    print(' 以退出')

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python如何獲取實(shí)時(shí)股票信息的方法示例

    Python如何獲取實(shí)時(shí)股票信息的方法示例

    本文主要介紹了Python如何獲取實(shí)時(shí)股票信息的方法示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • 使用Python實(shí)現(xiàn)tail的示例代碼

    使用Python實(shí)現(xiàn)tail的示例代碼

    tail是一個(gè)常用的Linux命令, 它可以打印文件的后面n行數(shù)據(jù), 也能實(shí)時(shí)輸出文件的追加數(shù)據(jù)。本文就來用Python實(shí)現(xiàn)tail,感興趣的可以了解一下
    2023-03-03
  • python實(shí)現(xiàn)自動(dòng)更換ip的方法

    python實(shí)現(xiàn)自動(dòng)更換ip的方法

    這篇文章主要介紹了python實(shí)現(xiàn)自動(dòng)更換ip的方法,涉及Python針對(duì)本機(jī)網(wǎng)絡(luò)配置的相關(guān)操作技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-05-05
  • 淺談Python面向?qū)ο缶幊蘯op思想心得

    淺談Python面向?qū)ο缶幊蘯op思想心得

    最近在給一個(gè)小表弟教Python,主要是給他推薦了本入門書籍自學(xué),大部分內(nèi)容都還算順利,到對(duì)象一節(jié)立馬抓瞎。當(dāng)然這也在我的預(yù)料之內(nèi),OOP本就是新手最難理解和掌握的部分
    2021-09-09
  • Python批量安裝卸載1000個(gè)apk的方法

    Python批量安裝卸載1000個(gè)apk的方法

    這篇文章主要介紹了Python批量安裝卸載1000個(gè)apk的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04
  • python中的計(jì)時(shí)器timeit的使用方法

    python中的計(jì)時(shí)器timeit的使用方法

    本篇文章主要介紹了python中的計(jì)時(shí)器timeit的使用方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-10-10
  • 如何將Python腳本打包成exe應(yīng)用程序介紹

    如何將Python腳本打包成exe應(yīng)用程序介紹

    大家好,本篇文章主要講的是如何將Python腳本打包成exe應(yīng)用程序介紹,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-02-02
  • Python中常見的三種字符串格式化輸出方法小結(jié)

    Python中常見的三種字符串格式化輸出方法小結(jié)

    字符串格式化是編程中一個(gè)常見的需求,它可以們將不同類型的數(shù)據(jù)插入到字符串中,在?Python?中,有多種方法可以執(zhí)行字符串格式化,本文為大家介紹了常見的三種方法,希望對(duì)大家有所幫助
    2024-02-02
  • pytorch中如何使用DataLoader對(duì)數(shù)據(jù)集進(jìn)行批處理的方法

    pytorch中如何使用DataLoader對(duì)數(shù)據(jù)集進(jìn)行批處理的方法

    這篇文章主要介紹了pytorch中如何使用DataLoader對(duì)數(shù)據(jù)集進(jìn)行批處理的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • Python3之讀取連接過的網(wǎng)絡(luò)并定位的方法

    Python3之讀取連接過的網(wǎng)絡(luò)并定位的方法

    下面小編就為大家分享一篇Python3之讀取連接過的網(wǎng)絡(luò)并定位的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04

最新評(píng)論