Skip to content

Instantly share code, notes, and snippets.

@aluzed
Created April 17, 2020 11:19
Show Gist options
  • Save aluzed/4eacd73a6a9e4df37fdf3a09c334811b to your computer and use it in GitHub Desktop.
Save aluzed/4eacd73a6a9e4df37fdf3a09c334811b to your computer and use it in GitHub Desktop.
Get file checksum in Python
import hashlib, sys
if len(sys.argv) != 3:
print('Error must have 2 args : python get_hash.py <algo> <filename>')
exit(1)
algo = sys.argv[1]
filename = sys.argv[2]
func = getattr(hashlib, algo)
if func is not None:
print(func(open(filename, 'rb').read()).hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment