一、使用场景
某些配置文件里有一些特定的字符,而这些字符恰巧需要我们采集出来,然后输出到另外一个窗口做展示时,可以使用该工具。
本例的演示则提取配置文件中的【姓名:黄蓉 女 九阴真经、姓名:郭靖 男 弹指神功】两行读取出来,读取其他内容也可以,更改相应参数即可。
二、实验文件
测试脚本:fielread.py
配置文件:john.conf
三、测试脚本代码
#! /usr/bin/env python3 # -*- coding:UTF-8 -*- from tkinter import * import tkinter ss = input('请输入搜索内容的开始首字符:') es = input('请输入搜索内容的结束首字符:') fp = input('请输入要搜索文件的路径:') def fetch(startStr,endStr,filePath): newLi = [] with open(filePath,'r',encoding='utf-8') as f : flag = False for line in f: if line.strip().startswith(startStr): flag = True if line.strip().startswith(endStr): flag = False if flag and line.strip(): newLi.append(line.strip()) return newLi info = fetch(ss,es,fp) # 调用fetch函数进行内容匹配,结果返回列表保存到info中 # [1]控制台打印输出 result = ' '.join(info) print(result) # [2]alert弹窗打印输出 root = Tk() # 创建窗口对象的背景颜色 new_info = Listbox(root) for item in info: new_info.insert(0,item) new_info.pack() root.mainloop()
四、配置文件内容
# # This file is part of John the Ripper password cracker, # Copyright (c) 1996-2006,2008-2013 by Solar Designer # # void init() { password_length = 16; /* Change this to match config */ int c, i; c = '0'; i = 0; while (c <= '9') numbers[i++] = c++; c = 'a'; i = 0; while (c <= 'z') lowers[i++] = c++; c = 'A'; i = 0; while (c <= 'Z') uppers[i++] = c++; /* symbols */ i = 0; symbols[i++] = '!'; symbols[i++] = '@'; symbols[i++] = '#'; symbols[i++] = '$'; symbols[i++] = '%'; symbols[i++] = '^'; symbols[i++] = '&'; symbols[i++] = '*'; symbols[i++] = '('; symbols[i++] = ')'; symbols[i++] = '~'; symbols[i++] = '-'; boundaries_charclass[i++] = 536870912; boundaries_charclass[i++] = 1073741824; boundaries_charclass[i++] = 1610612736; boundaries_charclass[i++] = 2147483647; 姓名:黄蓉 女 九阴真经 姓名:郭靖 男 弹指神功 备注: boundaries_numbers = 214748365 boundaries_numbers = 644245095 boundaries_numbers = 1073741824 boundaries_numbers = 1503238554 boundaries_numbers = 1932735284 boundaries_letters[i++] = 82595525; boundaries_letters[i++] = 165191050; boundaries_letters[i++] = 247786575; boundaries_letters[i++] = 330382100; boundaries_letters[i++] = 412977625; boundaries_letters[i++] = 495573150; } # End of john.conf file. # Keep this comment, and blank line above it, to make sure a john-local.conf # that does not end with is properly loaded.
五、执行效果
Console: 请输入搜索内容的开始首字符:姓名 请输入搜索内容的结束首字符:备注 请输入要搜索文件的路径:./john.conf 姓名:黄蓉 女 九阴真经 姓名:郭靖 男 弹指神功