netsh,阻止文本文件中的所有 IP 地址?

use*_*685 7 windows firewall windows-firewall netsh

有没有办法将.txt文件(每行都有 IP 地址)导入 Windows 防火墙?

我希望完全阻止每个 IP 地址。这也将提供一种简单的方法.txt(与 结合使用netsh)在文件中取消阻止 IP 地址。

我目前正在使用 Peerblock,但它有时会导致 CPU 上的一些负载。

Rik*_*Rik 6

像这样的东西?

将其另存为blockit.bat

@echo off
if "%1"=="list" (
  netsh advfirewall firewall show rule Blockit | findstr RemoteIP
  exit/b
)

:: Deleting existing block on ips
netsh advfirewall firewall delete rule name="Blockit"

:: Block new ips (while reading them from blockit.txt)
for /f %%i in (blockit.txt) do (
  netsh advfirewall firewall add rule name="Blockit" protocol=any dir=in action=block remoteip=%%i
  netsh advfirewall firewall add rule name="Blockit" protocol=any dir=out action=block remoteip=%%i
)

:: call this batch again with list to show the blocked IPs
call %0 list
Run Code Online (Sandbox Code Playgroud)

blockit.txt使用您的 IP创建一个以阻止和运行blockit.

您可以运行blockit list以检查当前阻止了哪些 IP。

注意:这需要以管理员身份运行。

编辑:不知道您是否想要阻止传出或传入流量,所以我添加了dir=indir=out。您可以删除其中一个(或两个方向都保留)。