python3指纹扫描病毒

通过指纹扫描病毒,将病毒指纹写在列表中

便利指定路径即可。

import hashlib

import os

# 预定义病毒哈希值列表

virus_hashes = ['25d55ad283aa400af464c76d713c07ad', '4e4d8b9721f0dceb3d3bf3a2a25962ab']

# 扫描指定目录下的所有文件,并计算其SHA256哈希值

def scan_files(path):

for root, dirs, files in os.walk(path):

for name in files:

filepath = os.path.join(root, name)

print(filepath)

try:

with open(filepath, 'rb') as f:

data = f.read()

file_hash = hashlib.sha256(data).hexdigest()

if file_hash in virus_hashes:

print('Virus found: ' + filepath)

else:

print('Safe file: ' + filepath)

<

你可能感兴趣的:(安全技术,Python,python,开发语言,全文检索)