0

This is fairly easy in Win7 because that version of Windows Firewall allows you to block a port range e.g. 1-79,81-65535, leaving only a single port open.

However Vista (at least by default) doesn't have this - you can only specify a comma separated list of affected ports, and typing 1,2,3,4,5,6,7,8,9,.....65530,65531,65532,65533,65534,65535 is going to take a while.

Is there any way around this?

1 Answer 1

2

There's no way around the 1 port at a time specification in Vista.

But you can add entries to the Firewall using the command-line command Netsh. And since you can do that, you can script/loop it to put in many entries at once.

Here's a one-liner that will add multiple port rules, one for each port:

for /l %i in (1,1,79) do netsh advfirewall firewall add rule name="PortRangeEntry%i" dir=in protocol=TCP localport=%i action=block

This will make 79 entries named "PortRangeentry1" thru "PortRangeEntry79", each set to block inbound TCP connections on that port.

for /l %i in (81,1,65535) do netsh advfirewall firewall add rule name="PortRangeEntry%i" dir=in protocol=TCP localport=%i action=block

Will do ports 81-65535.

These have to be run "as administrator" and while I tested it on Windows 8, the same or very similar should work for Vista.

1
  • FWIW you can add ~1000 ports at a time, resulting in only 130 rules (one set each for TCP and UDP), rather than 65,000 rules.
    – steve cook
    Jul 17, 2013 at 2:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .