defFind_Repeat_File(file_path,file_type): Catalogue = os.listdir(file_path) CatalogueDict = {} # 查询字典,方便后期查询键值对对应参数 for each in Catalogue: path = (file_path + each) if os.path.splitext(path)[1] == file_type: withopen(path,"rb") as fp: crc32 = zlib.crc32(fp.read()) # print("[*] 文件名: {} CRC32校验: {}".format(path,str(crc32))) CatalogueDict[each] = str(crc32) CatalogueList = [] for value in CatalogueDict.values(): # 该过程实现提取字典中的crc32特征组合成列表 CatalogueList CatalogueList.append(value)
CountDict = {} for each in CatalogueList: # 该过程用于存储文件特征与特征重复次数,放入 CountDict CountDict[each] = CatalogueList.count(each) RepeatFileFeatures = [] for key,value in CountDict.items(): # 循环查找字典中的数据,如果value大于1就存入 RepeatFileFeatures if value > 1: print("[-] 文件特征: {} 重复次数: {}".format(key,value)) RepeatFileFeatures.append(key)
if __name__ == "__main__": Find_Repeat_File("D://lyshark/",".png")
before = dict([(f, None) for f in os.listdir(path_to_watch)]) whileTrue: time.sleep (0.3)
after = dict ([(f, None) for f in os.listdir (path_to_watch)]) added = [f for f in after ifnot f in before] removed = [f for f in before ifnot f in after]
# 新增文件时触发 if added: # print("新建文件: {}".format(added)) for index inrange(0,len(added)): # 计算文件CRC32 AbsolutePath = path_to_watch + "/" + added[index] crc = Calculation_crc32(AbsolutePath) print(f"计算文件路径: {AbsolutePath} 文件CRC32: {crc}")
# 只要有新文件则加入到crc_pool if crc != 0: crc_poll.append(crc)
print("池内数据: {}".format(crc_poll)) crc_count = 0
# 循环池内的所有CRC数据 for index inrange(0,len(crc_poll)):