Skip to content

Instantly share code, notes, and snippets.

@ehindiayleau
Last active June 27, 2026 15:23
Show Gist options
  • Select an option

  • Save ehindiayleau/507e33e18ea5f15bff250708f2722c43 to your computer and use it in GitHub Desktop.

Select an option

Save ehindiayleau/507e33e18ea5f15bff250708f2722c43 to your computer and use it in GitHub Desktop.
Inject Multiple IP Addresses Into A Single Windows Firewall Rule With A Batch and Text File
@echo off
if "%1"=="list" (
netsh advfirewall firewall show rule multiple_ip_to_fw_rule | findstr RemoteIP
exit/b
)
netsh advfirewall firewall delete rule name="multiple_ip_to_fw_rule"
for /f %%i in (C:\PATH_TO_TEXT_FILE_WITH_IP_ADDRESSES\multiple_ip_to_fw_rule.txt) do (
netsh advfirewall firewall add rule name="multiple_ip_to_fw_rule" protocol=any dir=in action=block remoteip=%%i
netsh advfirewall firewall add rule name="multiple_ip_to_fw_rule" protocol=any dir=out action=block remoteip=%%i
)
call %0 list
pause
199.7.91.0/24,192.203.230.0/24,192.112.36.0/24,198.97.192.0/21,198.97.184.0/21,198.97.180.0/22
@ehindiayleau

Copy link
Copy Markdown
Author

The text file containing the IP addresses must be comma separated addresses in a single line with no spaces in order to be injected into a single rule. Any spaces will cause a new rule with the same name to be created. Can be single IP addresses, ranges, or CIDR format. Windows firewall has a limit of no more than 1000 addresses per a rule I believe, therefore the IP list will throw a;

No rules match the specified criteria.

Press any key to continue . . .

if the limit is succeeded.

@b4tavir

b4tavir commented Jun 27, 2026

Copy link
Copy Markdown

thanks for this man

@b4tavir

b4tavir commented Jun 27, 2026

Copy link
Copy Markdown

Skip to content

Search Gists
Search...
All gists
Back to GitHub
@ehindiayleau
ehindiayleau/multiple_ip_to_fw_rule.bat
Last active now • Report abuse
Code
Revisions
2
Stars
6
Forks
1
Clone this repository at <script src="https://gist.github.com/ehindiayleau/507e33e18ea5f15bff250708f2722c43.js&quot;&gt;&lt;/script>

<script src="https://gist.github.com/ehindiayleau/507e33e18ea5f15bff250708f2722c43.js"></script>

Inject Multiple IP Addresses Into A Single Windows Firewall Rule With A Batch and Text File
multiple_ip_to_fw_rule.bat
@echo off
if "%1"=="list" (
netsh advfirewall firewall show rule multiple_ip_to_fw_rule | findstr RemoteIP
exit/b
)

netsh advfirewall firewall delete rule name="multiple_ip_to_fw_rule"

for /f %%i in (C:\PATH_TO_TEXT_FILE_WITH_IP_ADDRESSES\multiple_ip_to_fw_rule.txt) do (
netsh advfirewall firewall add rule name="multiple_ip_to_fw_rule" protocol=any dir=in action=block remoteip=%%i
netsh advfirewall firewall add rule name="multiple_ip_to_fw_rule" protocol=any dir=out action=block remoteip=%%i
)

call %0 list

pause
multiple_ip_to_fw_rule.txt
199.7.91.0/24,192.203.230.0/24,192.112.36.0/24,198.97.192.0/21,198.97.184.0/21,198.97.180.0/22
Load earlier comments...
@b4tavir
b4tavir
commented
now
thanks for this man

@b4tavir
Comment

Leave a comment
Footer
© 2026 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Community
Docs
Contact
Manage cookies
Do not share my personal information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment