netsh, block all IP addresses in a text file?
Is there a way for me to import a .txt
file (with IP addresses on each line) into Windows Firewall?
I want each of the IP addresses to be completely blocked. That would also provide an easy way to unblock an IP address in the .txt
file later on (in combination with netsh
).
I am currently using Peerblock but it tends to cause some load on the CPU sometimes.
Solution 1:
Something like this?
Save this as 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
Create a blockit.txt
with your IPs to block and run blockit
.
You can run blockit list
to check which IPs are blocked at the moment.
Note: This needs to be run as Administrator.
Edit: Didn't know if you wanted outgoing or incoming traffic blocked so i added both dir=in
and dir=out
. You can delete one or the other (or leave them both for both directions).