Skip to content

Instantly share code, notes, and snippets.

@K0G0
Last active July 5, 2019 18:04
Show Gist options
  • Select an option

  • Save K0G0/45e76f0c60a8438ac8d6 to your computer and use it in GitHub Desktop.

Select an option

Save K0G0/45e76f0c60a8438ac8d6 to your computer and use it in GitHub Desktop.
Basic File Integrity Monitor
import os,hashlib
for file in [item for item in os.listdir('.') if os.path.isfile(item)]:
hash = hashlib.md5()
with open(file) as f:
for chunk in iter(lambda: f.read(2048), ""):
hash.update(chunk)
md5 = hash.hexdigest()
print file,md5
import os,hashlib,time
files={}
while True:
for file in [item for item in os.listdir('.') if os.path.isfile(item)]:
hash = hashlib.md5()
with open(file) as f:
for chunk in iter(lambda: f.read(2048), ""):
hash.update(chunk)
md5 = hash.hexdigest()
if file in files and md5 <> files[file]:
print '%s\t%s has been changed!'%(time.strftime("%Y-%m-%d %H:%M:%S") , file)
files[file]=md5
time.sleep(1)
import os,hashlib,time
files={}
for file in [item for item in os.listdir('.') if os.path.isfile(item)]:
hash = hashlib.md5()
with open(file) as f:
for chunk in iter(lambda: f.read(2048), ""):
hash.update(chunk)
md5 = hash.hexdigest()
if file in files and md5 <> files[file]:
print '%s\t%s has been changed!'%(time.strftime("%Y-%m-%d %H:%M:%S") , file)
files[file]=md5
import os
for file in [item for item in os.listdir('.') if os.path.isfile(item)]:
print file
import os,hashlib,time
files={}
for file in [item for item in os.listdir('.') if os.path.isfile(item)]:
hash = hashlib.md5()
with open(file) as f:
for chunk in iter(lambda: f.read(2048), ""):
hash.update(chunk)
md5 = hash.hexdigest()
print '%s\t%s has been changed!'%(time.strftime("%Y-%m-%d %H:%M:%S") , file)
files[file]=md5
import os,hashlib
files={}
for file in [item for item in os.listdir('.') if os.path.isfile(item)]:
hash = hashlib.md5()
with open(file) as f:
for chunk in iter(lambda: f.read(2048), ""):
hash.update(chunk)
md5 = hash.hexdigest()
files[file]=md5
print files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment