Last active
November 26, 2015 01:40
-
-
Save K0G0/32553b470ccb89b29cde to your computer and use it in GitHub Desktop.
AdvancedFIM_CalculateHash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os,hashlib,time,base64 | |
| monitor=[ | |
| {'path':'E:\Dropbox\SVL\Projects\AdvancedFIM_GatherFiles','recursive':True}, | |
| {'path':'E:\Dropbox\SVL\Projects','recursive':False}, | |
| {'path':'E:\Dropbox\SVL\Projects\BasicFIM\BasicFIM.py','recursive':False} | |
| ] | |
| files={} | |
| def getFiles(): | |
| filesList=[] | |
| for x in monitor: | |
| if os.path.isdir(x['path']): | |
| if x['recursive']: | |
| filesList.extend([os.path.join(root, f) for (root, dirs, files) in os.walk(x['path']) for f in files]) | |
| else: | |
| filesList.extend([item for item in os.listdir(x['path']) if os.path.isfile(item)]) | |
| elif os.path.isfile(x['path']): | |
| filesList.append(x['path']) | |
| return filesList | |
| def getBytes(file): | |
| return base64.b64encode(open(file, "rb").read()) | |
| while True: | |
| for file in getFiles(): | |
| hash = hashlib.sha256() | |
| with open(file) as f: | |
| for chunk in iter(lambda: f.read(2048), ""): | |
| hash.update(chunk) | |
| sha256 = hash.hexdigest() | |
| if file in files and sha256 <> files[file]['sha256']: | |
| print '%s\t%s has been changed!'%(time.strftime("%Y-%m-%d %H:%M:%S") , file) | |
| files[file]={'sha256':sha256,'bytes':getBytes(file)} | |
| time.sleep(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os,hashlib,base64 | |
| file='E:\Dropbox\SVL\Projects\BasicFIM\BasicFIM.py' | |
| def getBytes(file): | |
| return base64.b64encode(open(file, "rb").read()) | |
| print getBytes(file) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os,hashlib,time | |
| monitor=[ | |
| {'path':'E:\Dropbox\SVL\Projects\AdvancedFIM_GatherFiles','recursive':True}, | |
| {'path':'E:\Dropbox\SVL\Projects','recursive':False}, | |
| {'path':'E:\Dropbox\SVL\Projects\BasicFIM\BasicFIM.py','recursive':False} | |
| ] | |
| files={} | |
| def getFiles(): | |
| filesList=[] | |
| for x in monitor: | |
| if os.path.isdir(x['path']): | |
| if x['recursive']: | |
| filesList.extend([os.path.join(root, f) for (root, dirs, files) in os.walk(x['path']) for f in files]) | |
| else: | |
| filesList.extend([item for item in os.listdir(x['path']) if os.path.isfile(item)]) | |
| elif os.path.isfile(x['path']): | |
| filesList.append(x['path']) | |
| return filesList | |
| while True: | |
| for file in getFiles(): | |
| hash = hashlib.sha256() | |
| with open(file) as f: | |
| for chunk in iter(lambda: f.read(2048), ""): | |
| hash.update(chunk) | |
| sha256 = hash.hexdigest() | |
| if file in files and sha256 <> files[file]: | |
| print '%s\t%s has been changed!'%(time.strftime("%Y-%m-%d %H:%M:%S") , file) | |
| files[file]=sha256 | |
| time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment