-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHash Finder
32 lines (24 loc) · 1.01 KB
/
Hash Finder
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
import os, hashlib
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--path', help='path to folder', default='./')
parser.add_argument('-o', '--output', help='output file (default: "./hashes")', default='./hashes')
parser.add_argument('-b', '--bytes', help='Bytes size for read files (default: 8192)', default=8192, type=int)
args = parser.parse_args()
if args.path[-1] != '/':
args.path += '/'
hashes = []
output = open(args.output, 'w')
for top, dirs, files in os.walk(args.path):
for nm in files:
file_name = os.path.join(top, nm).replace("\\", "/")
with open(file_name, 'rb') as file_to_check:
md5_r = hashlib.md5()
for chunk in iter(lambda: file_to_check.read(args.bytes), b""):
md5_r.update(chunk)
md5_returned = md5_r.hexdigest()
hashes.append([file_name[len(args.path):], md5_returned])
print("Files: " + str(len(hashes)))
for h in hashes:
output.write(' '.join(h) + '\n')
print(' '.join(h))