-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinchecksumpy.py
More file actions
37 lines (29 loc) · 946 Bytes
/
winchecksumpy.py
File metadata and controls
37 lines (29 loc) · 946 Bytes
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
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 3 20:24:43 2018
@author: vince
"""
import os
import sys
import hashlib
#Assumptions for now
certtype = 'md5'
#Get location of Dropped File to pass to windows CertUtil
droppedFile = sys.argv[1]
print(droppedFile)
#Get Expected MD5 checksum and run windows CertUtil on Dropped File
md5Exp = input("Enter Expected MD5 Checksum: ")
#Load File for hashlib - Will hash string if left alone
with open(droppedFile, 'rb') as file_handle:
file_contents = file_handle.read()
md5Act = hashlib.md5(file_contents).hexdigest().upper()
print('Actual '+certtype+' hash is: '+md5Act)
#Compare and Exit or ask user to delete
if md5Exp == md5Act:
print('File matches '+certtype+' checksum.')
else:
print('File does NOT match '+certtype+' checksum.')
if input('Delete[y/n]: ') == 'y':
os.remove(droppedFile)
print(droppedFile+' deleted')
input('Hit any key to exit')