python获取目录下所有exe并导出火绒禁网规则json文件

2022/2/22 12:58:04

本文主要是介绍python获取目录下所有exe并导出火绒禁网规则json文件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

使用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")



这篇关于python获取目录下所有exe并导出火绒禁网规则json文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程