使用python获取指定目录下所有exe文件,并生成火绒可导入的json文件,将之导入火绒安全设置--系统防护--联网控制中,从而实现应用禁网
from pathlib import Path import json mdirs = [ r"D:\Tools", ] def find_all_exe(dirs): files = [] for dir_cur in dirs: p = Path(dir_cur).rglob("*.exe") for i in p: # print(i) # 获取地址字符串 file_path = str(i) # 地址转义 new_file = "\\".join(file_path.split("\\")) files.append(new_file) return files def format_data_to_huorong(data_lst): res_dict = { "ver": "5.0", "tag": "appnetctrl", "data": [] } for path in data_lst: cur_dict = {"procname": path, "block": True} res_dict["data"].append(cur_dict) return res_dict def dict_to_json_write_file(dict): with open('火绒规则生成.json', 'w', encoding="utf-8") as f: json.dump(dict, f, indent=2) f.write("\r\n") def save_files(container, file_type="txt"): with open(f"result.{file_type}", "w", encoding="utf-8") as f: f.write(str(container).replace("',", "',\n")) if __name__ == '__main__': print("begin") all_files = find_all_exe(mdirs) # save_files(all_files) huorong_dict = format_data_to_huorong(all_files) dict_to_json_write_file(huorong_dict) print("done")