微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐