python實(shí)現(xiàn)文件快照加密保護(hù)的方法
本文實(shí)例講述了python實(shí)現(xiàn)文件快照加密保護(hù)的方法。分享給大家供大家參考。具體如下:
這段代碼可以對(duì)指定的目錄進(jìn)行掃描,包含子目錄,對(duì)指定擴(kuò)展名的文件進(jìn)行SHA-1加密后存儲(chǔ)在cvs文件,以防止文件被篡改
調(diào)用方法:python snapper.py > todayCheck.csv
# Hello, this is a script written in Python. See http://www.pyhon.org # # Snapper 1.2p # # This script will walk a directory (and its subdirectories) and compute # SHA (Secure Hash Algorithm) for specific files (according to their # extensions) and ouput a CSV file (suited for loading into a spreadsheet # editor,a database or simply comparing with diff or ExamDiff.). # # You can redirect the output of this script to a file. # eg. python snapper.py > todayCheck.csv # # This script can be usefull to check system files tampering. # # This script is public domain. Feel free to reuse it. # The author is: # Sebastien SAUVAGE # <sebsauvage at sebsauvage dot net> # http://sebsauvage.net # # More quick & dirty scripts are available at http://sebsauvage.net/python/ # # Directory to scan and extensions are hardcoded below: directoryStart = r'c:\windows' extensionList=['.exe','.dll','.ini','.ocx','.cpl','.vxd','.drv','.vbx','.com','.bat','.src', '.sys','.386','.acm','.ax', '.bpl','.bin','.cab','.olb','.mpd','.pdr','.jar'] import os,string,sha,stat,sys def snapper ( directoryStart , extensionList ) : os.path.walk( directoryStart, snapper_callback, extensionList ) def snapper_callback ( extensionList , directory, files ) : sys.stderr.write('Scanning '+directory+'\n') for fileName in files: if os.path.isfile( os.path.join(directory,fileName) ) : if string.lower(os.path.splitext(fileName)[1]) in extensionList : filelist.append(fileSHA ( os.path.join(directory,fileName) )) def fileSHA ( filepath ) : sys.stderr.write(' Reading '+os.path.split(filepath)[1]+'\n') file = open(filepath,'rb') digest = sha.new() data = file.read(65536) while len(data) != 0: digest.update(data) data = file.read(65536) file.close() return '"'+filepath+'",'+str(os.stat(filepath)[6])+',"'+digest.hexdigest()+'"' sys.stderr.write('Snapper 1.1p - http://sebsauvage.net/python/\n') filelist = [] snapper( directoryStart , extensionList ) sys.stderr.write('Sorting...\n') filelist.sort() filelist.insert(0, '"File path","File size","SHA"' ) sys.stderr.write('Printing...\n') for line in filelist: print line sys.stderr.write('All done.\n')
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
python字典與json轉(zhuǎn)換的方法總結(jié)
在本篇文章里小編給大家整理的是一篇關(guān)于python字典與json轉(zhuǎn)換的方法總結(jié)內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2020-12-12Django自定義用戶(hù)表+自定義admin后臺(tái)中的字段實(shí)例
今天小編就為大家分享一篇Django自定義用戶(hù)表+自定義admin后臺(tái)中的字段實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11Python如何使用print()函數(shù)輸出格式化字符串
Python中內(nèi)置的%操作符和format函數(shù),都可以用于格式化字符串,下面這篇文章主要給大家介紹了關(guān)于Python如何使用print()函數(shù)輸出格式化字符串的相關(guān)資料,需要的朋友可以參考下2021-08-08Python爬蟲(chóng)實(shí)現(xiàn)百度翻譯功能過(guò)程詳解
這篇文章主要介紹了Python爬蟲(chóng)實(shí)現(xiàn)百度翻譯功能過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05pycharm社區(qū)版安裝node.js插件運(yùn)行js代碼方法
PyCharm可以說(shuō)是當(dāng)今最流行的一款Python IDE了,下面這篇文章主要給大家介紹了關(guān)于pycharm社區(qū)版安裝node.js插件運(yùn)行js代碼的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-10-10基于Python實(shí)現(xiàn)主機(jī)遠(yuǎn)程控制
這篇文章主要介紹了基于Python實(shí)現(xiàn)主機(jī)遠(yuǎn)程控制,本文為?HITwh?網(wǎng)絡(luò)空間安全專(zhuān)業(yè)網(wǎng)絡(luò)空間安全設(shè)計(jì)與實(shí)踐選題,主要實(shí)現(xiàn)了遠(yuǎn)程監(jiān)控局域網(wǎng)內(nèi)的主機(jī)桌面與網(wǎng)絡(luò)情況、簡(jiǎn)單鍵鼠控制、遠(yuǎn)程斷網(wǎng)(ARP?攻擊)、數(shù)據(jù)加密傳輸?shù)裙δ埽旅鎭?lái)看看具體實(shí)現(xiàn)過(guò)程吧2022-01-01Python AutoCAD 系統(tǒng)設(shè)置的實(shí)現(xiàn)方法
這篇文章主要介紹了Python AutoCAD 系統(tǒng)設(shè)置的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04