文件完整性hash验证demo(python脚本)
一个简单的文件完整性hash验证脚本
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import hashlib import json #网站目录所有文件列表 path_list=[] #静态文件可以不做hash效验 White_list=['.js','.jpg','.png','.html','.htm'] def GetFile(path): for dirpath, dirnames, filenames in os.walk(path): for dirname in dirnames: dir=os.path.join(dirpath, dirname) #print dir path_list.append(dir) for filename in filenames: file=os.path.join(dirpath, filename) if os.path.splitext(file)[1] not in White_list: #print file path_list.append(file) return path_list #使用文件迭代器,循环获取数据 def md5sum(file): m=hashlib.md5() if os.path.isfile(file): f=open(file,'rb') for line in f: m.update(line) f.close else: m.update(file) return (m.hexdigest()) def Get_md5result(webpath): pathlist=GetFile(webpath) md5_file={} for file in pathlist: md5_file[file]=md5sum(file) json_data=json.dumps(md5_file) fileObject = open('result.json', 'w') fileObject.write(json_data) fileObject.close() def load_data(json_file): model={} with open(json_file,'r') as json_file: model=json.load(json_file) return model def Analysis_dicts(dict1,dict2): keys1 = dict1.keys() keys2 = dict2.keys() ret1 = [ i for i in keys1 if i not in keys2] ret2 = [ i for i in keys2 if i not in keys1] print u"可能被删除的文件有:" for i in ret1: print i print u"新增的文件有:" for i in ret2: print i print u"可能被篡改的文件有:" ret3=list((set(keys1).union(set(keys2)))^(set(keys1)^set(keys2))) for key in ret3: if key in keys1 and key in keys2: if dict1[key] == dict2[key]: pass else: print key if __name__ == '__main__': webpath = raw_input("Please enter your web physical path, for example, c:\\wwww]. ").lower() Get_md5result(webpath) dict2=load_data("result.json") methodselect= raw_input("[?] Check the integrity of the file: [Y]es or [N]O (Y/N): ").lower() if methodselect == 'y': file=raw_input("Please enter the hash file path to be compared: ").lower() dict1=load_data(file) Analysis_dicts(dict1,dict2) elif methodselect == 'n': exit()
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
python:函数中五花八门的参数形式(茴香豆的『回』字有四种写法)
毫不夸张的说,python语言中关于函数参数的使用,是我见过最为灵活的,随便怎么玩都可以,本文以数学乘法为例,演示几种不同的传参形式: 一、默认参数 def multiply1(x, y): return x * y print("multiply1:", multiply1(2, 3)) 输出 multiply1: 6 ,这是最平淡无奇的函数写法。 python支持默认参数,比如:如果想让1个数自动乘10,又不想定义新的函数,上面的代码,可以改成: def multiply1(x, y=10): return x * y print("multiply1:", multiply1(2, 3)) print("multiply1:", multiply1(2)) 输出 multiply1: 6multiply1: 20 另外,调用函数时,除了按顺序依次给值外,还可以“显式”的命名传值,示例如下: print("multiply1:", multiply1(x=2, y=4)) print("multiply1:", multiply1(y=3, x=5)) print("multipl...
- 下一篇
消息队列深入解析
消息队列和消息 “消息队列”(Message queue)是在消息的传输过程中保存消息的容器。“消息” 是在两台计算机间传送的数据单位。消息可以非常简单,例如只包含文本字符串;也可以更复杂,可能包含嵌入对象。 常见的消息队列有那些? 当前使用较多的消息队列有RabbitMQ、ActiveMQ、RocketMQ、Kafka等等,我们之前提高的redis数据库也可以实现消息队列,不过不推荐,redis本身设计就不是用来做消息队列的。 使用消息队列的场景和好处 《大型网站技术架构》第四章和第七章均有提到消息队列对应用性能及扩展性的提升。 1.通过异步处理提高系统性能 如上图,在不使用消息队列服务器的时候,用户的请求数据直接写入数据库,在高并发的情况下数据库压力剧增,使得响应速度变慢。但是在使用消息队列之后,用户的请求数据发送给消息队列之后立即 返回,再由消息队列的消费者进程从消息队列中获取数据,异步写入数据库。由于消息队列服务器处理速度快于数据库(消息队列也比数据库有更好的伸缩性),因此响应速度得到大幅改善。 通过以上分析我们可以得出消息队列具有很好的削峰作用的功能——即通过异步处理,将短时...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Linux系统CentOS6、CentOS7手动修改IP地址
- Red5直播服务器,属于Java语言的直播服务器
- CentOS7,8上快速安装Gitea,搭建Git服务器
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题