Windows Firewall – Creating list of ports using bash

Written by James McDonald

July 6, 2011

Today I tried to add a firewall rule in Windows 2008 using syntax such as 1024-2000 and got an error message saying that I had to specify the ports correctly.

Seems that it doesn’t allow an inclusive range but you need to specify each port individually such as 1024,1025, etc. I don’t know about you but I have better things to do than do that manually.

Using Bash under Cygwin:

for i in {1024..2000} ; do echo -n $i, ; done > list.txt
# then open list.txt in notepad.exe remove 
# the trailing comma and copy and paste the
# list into Windows Advanced Firewall GUI

Using a VBS Scriptlet:

' copy this into a vbs script and run 
' from command prompt using cscript yourscriptname.vbs
for i = 1024 to 2000
	port_list = port_list & i & ","

' trim the trailing comma
wscript.echo left( port_list, len(port_list )-1)


Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Meraki Open Source Licenses

Until today I assumed that Meraki was built in-house with only closed source software. But having a look at the...


If you have Veeam backup failing with the Updating BCD failed with Cannot update SafeBoot flag and SentinelOne is...