适用于 Windows 的 Python 防火墙? [英] Python Firewall for Windows?

查看:57
本文介绍了适用于 Windows 的 Python 防火墙?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 python 为 Windows 编写一个小型的自定义防火墙.如果有人能指出我实现这一目标的正确方向,我会很高兴.我想要阻止/解除阻止 IP 和端口.

I want to write a tiny custom firewall for windows, in python. I would be very glad if someone can point me in the right direction to achieve this. I would like to have block/unblock IP and Port.

推荐答案

使用python的subprocess模块​​运行如下命令提示符/powershell命令:

将 Windows 防火墙服务配置为自动启动.

Use python's subprocess module to run the following command prompt / powershell commands:

Configure the Windows firewall service to start automatically.

sc config mpssvc start=auto

启动 Windows 防火墙服务.

Start the Windows firewall service.

net stop mpssvc && net start mpssvc

启用 Windows 防火墙配置文件.

Enable the Windows firewall profiles.

netsh advfirewall set allprofiles state on

创建防火墙规则以拒绝来自特定 IP 地址的数据包输入.

Create a firewall rule to deny the input of packets from a specific IP address.

netsh advfirewall firewall add rule name="BLOCK IP ADDRESS - 10.10.10.10" dir=in action=block remoteip=10.10.10.10

创建防火墙规则以拒绝向特定 IP 地址输出数据包.

Create a firewall rule to deny the output of packets to a specific IP address.

netsh advfirewall firewall add rule name="BLOCK IP ADDRESS - 10.10.10.10" dir=out action=block remoteip=10.10.10.10

这篇关于适用于 Windows 的 Python 防火墙?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆