-
Notifications
You must be signed in to change notification settings - Fork 24
/
FindEverything-py2.py
69 lines (60 loc) · 2.44 KB
/
FindEverything-py2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import argparse
def logo():
logo0 = '''
_______ ______ _____ ____ __
/ ____(_)___ ____/ / __ \/ ___/ / __ \__ __/ /_
/ /_ / / __ \/ __ / / / /\__ \______/ / / / / / / __/
/ __/ / / / / / /_/ / /_/ /___/ /_____/ /_/ / /_/ / /_
/_/ /_/_/ /_/\__,_/\____//____/ \____/\__,_/\__/
'''
print(logo0)
def search_files(directory, extensions):
files = []
for root, _, filenames in os.walk(directory):
for filename in filenames:
for extension in extensions:
if filename.endswith(extension):
files.append(os.path.join(root, filename))
return files
def search_content(file_path, content):
matching_lines = []
try:
with open(file_path, 'r') as file:
for line_num, line in enumerate(file, 1):
try:
if content in line:
matching_lines.append((line_num, line))
except UnicodeDecodeError as e:
print("[-] Unicode decode error in file %s, line %d: %s" % (file_path, line_num, e))
return matching_lines
except:
print("[-] Error file %s" % (file_path))
def write_to_file(output_file, file_path, matching_lines):
with open(output_file, 'a') as f:
f.write("[+] File Path: %s\n" % file_path)
f.write("[=] Line Rows: %d\n" % len(matching_lines))
for line_num, line in matching_lines:
f.write("[~] In Line %d: %s\n" % (line_num, line.strip()))
f.write("\n")
def main():
parser = argparse.ArgumentParser(description="FindOS-Out")
parser.add_argument("-n", "--name", help="Specify the suffix", required=True)
parser.add_argument("-c", "--content", help="Specify file content", required=True)
parser.add_argument("-o", "--output", help="Specify output file", default="findout.txt")
parser.add_argument("-d", "--directory", help="Target directory", default="./")
args = parser.parse_args()
directory = args.directory
extensions = args.name.split(',')
content = args.content
output_file = args.output
files = search_files(directory, extensions)
for file_path in files:
matching_lines = search_content(file_path, content)
if matching_lines:
write_to_file(output_file, file_path, matching_lines)
if __name__ == "__main__":
logo()
print("[+] Runing Search..")
main()
print("[+] Out to findout.txt..")