Answers for "block ip address windows firewall using powershell from text file"

0

block ip address windows firewall using powershell from text file

@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
Posted by: Guest on February-19-2022

Code answers related to "block ip address windows firewall using powershell from text file"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language