Hi, I'm looking for a cmd or batch script to be able to add a list of IP addresses to block the outbound connection through Windows firewall. Any help will be greatly appreciated. Thanks
Example https://forums.mydigitallife.net/posts/848696/ Code: netsh advfirewall firewall add rule name="KMSBLOCK" protocol=any dir=out remoteip=65.52.98.231,65.52.98.232,65.52.98.233 action=block
@abbodi1406 Thanks. Can I use the Ip's as a downward list instead of a aligned list ? Example: 65.52.98.231, 65.52.98.232, 65.52.98.233
No you can use this workaround: Code: set ips=^ 65.52.98.231,^ 65.52.98.232,^ 65.52.98.233 netsh advfirewall firewall add rule name="KMSBLOCK" protocol=any dir=out remoteip=%ips% action=block
Oh! how am I gonna add ^ at the end of a very long list that needs editing every so often. I understand there's a way to easily batch rename the files but not when when the last digit is different with every server address. Thank you for the support. Highly appreciated.
Try Notepad3 or Notepad++ if the list is simple text file, you can use this batch to set the required IPs Code: @echo off reg query HKU\S-1-5-19 >nul 2>nul || goto :eof setlocal EnableDelayedExpansion cd /d "%~dp0" for /f "tokens=* delims=" %%a in (list.txt) do ( if defined _ips (set "_ips=!_ips!,%%a") else (set "_ips=%%a") ) netsh advfirewall firewall delete rule name="IPsBlock" 2>nul netsh advfirewall firewall add rule name="IPsBlock" protocol=any dir=out remoteip=%_ips% action=block pause
@abbodi1406 you're a life saver. Thank you. Just one last think. Where should I put my list ? I tried putting it in the same directory as "list.txt" but the batch gave an error that one or other rule does not meet the criteria. I'm not placing the list in the right place. Place help me just this once. And thanks again.
Okay the error went away. Had a few empty lines at the start of the list but I can still access the IP I had in the list, they're not blocked. I shouldn't get a reply from ping. Update: Batch from @abbodi1406 is working as intended. Thanks man, highly appreciated. What happens if I run this again ? I keep adding entries to this list, what will happen to the older ones ?