Add Windows Firewall rule for multiple IP's using netsh.exe

1.4k views Asked by At
echo@
netsh advfirewall firewall add rule name="test" dir=in action=block protocol=TCP remoteip=16.24.0.0/24,**from 157.175.0.0 to 157.175.255.255**,**from 15.184.0.0 to 15.184.255.255**,**from 15.185.0.0 to 15.185.255.255**
netsh advfirewall firewall add rule name="test" dir=out action=block protocol=TCP remoteip=16.24.0.0/24,**from 157.175.0.0 to 157.175.255.255**,**from 15.184.0.0 to 15.184.255.255**,**from 15.185.0.0 to 15.185.255.255**
start wf.msc
pause

I'm trying create a Windows batch file which can block IP addresses in my firewall.

It's working when I use one IP, but I need to block ranges, not only one. For example the range 15.185.0.0 to 15.185.255.255.

1

There are 1 answers

0
SPOTENK On

this is the answer to my question

echo@
netsh advfirewall firewall add rule name="example" dir=in action=block protocol=TCP remoteip=16.24.0.0/24,157.175.0.0-157.175.255.255,15.184.0.0-15.184.255.255,15.185.0.0-15.185.255.255
netsh advfirewall firewall add rule name="example" dir=out action=block protocol=TCP remoteip=16.24.0.0/24,157.175.0.0-157.175.255.255,15.184.0.0-15.184.255.255,15.185.0.0-15.185.255.255
start wf.msc
pause