
I am a novice specialist, can someone tell me how to make a script correctly. To output MD5, SHA1, SHA256 to a separate file OUT.txt
All files in the directory
#!/usr/bin/python
import hashlib
import os
import sys
import checksumdir
import dirhash
from checksumdir
directory = 'C:UsersAdminDocumentsPosrtgerSQLRhel7'
md5hash = dirhash(directory, 'md5')
sha1hash = dirhash(directory, 'sha1', excluded_files=['package.json'])
sha256hash = dirhash(directory, 'sha256', excluded_extensions=['pyc'])
if len(sys.argv) < 2:
sys.exit('Usage: %s filename' % sys.argv[0])
if not os.path.exists(sys.argv[1]):
sys.exit('ERROR: File "%s" was not found!' % sys.argv[1])
with open(sys.argv[1], 'rb') as f:
sha1 = hashlib.sha1()
sha256 = hashlib.sha256()
md5 = hashlib.md5()
while True:
chunk = f.read(16 * 1024)
if not chunk:
break
sha1.update(chunk)
sha256.update(chunk)
md5.update(chunk)
print("SHA1: %s" % sha1.hexdigest())
print("SHA256: %s" % sha256.hexdigest())
print("MD5: %s" % md5.hexdigest())
try:
input("Press enter to terminate the program")
hash = checksumdir.dirhash("c:temp")
except:
pass