Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # ChecksumChecker.py
- # Author: Abdul Fatir
- # E-Mail: abdulfatirs@gmail.com
- from threading import Thread
- import hashlib
- import optparse
- def getChecksum(file_path,check_hash):
- file_handle = open(file_path,"rb")
- _md5 = hashlib.md5()
- while True:
- _buffer = file_handle.read()
- if not _buffer:
- break
- _md5.update(_buffer)
- digest = _md5.hexdigest()
- print "[+] File's MD5 checksum is: "+digest
- if (check_hash != None):
- if(check_hash.lower() == digest):
- print "[+] Hash matched: The file is authentic."
- else:
- print "[-] Hash mis-match: The file is not authentic."
- def Main():
- parser = optparse.OptionParser('usage: %prog -f <filename> [-m <md5 hash>]')
- parser.add_option('-f', dest='file_path', type='string', help='Please specify a file')
- parser.add_option('-m', dest='check_hash', type='string')
- (options,arg) = parser.parse_args()
- if (options.file_path == None):
- print parser.usage
- exit(0)
- else:
- file_path = options.file_path
- check_hash = options.check_hash
- print "[*] Hashing file '"+ file_path +"'...."
- hash_thread = Thread(target=getChecksum,args=(file_path,check_hash))
- hash_thread.start()
- hash_thread.join()
- if __name__ == '__main__':
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement