Thursday, May 19, 2011

Open / Close firewall on Windows 7 via Batch script

Because I am a paranoid SOB I normally lock down my Windows 7 firewall for any kind of incoming and outgoing traffic. Only for programs that really need to connect to the big bad web I define custom firewall rules.
But sometimes I need to allow outgoing traffic for getting program updates or using a service that requires an internet connection. To click throuth the GUI in Windows to finally get to the firewall settings is kind of annoying. So I wrote two little batch scripts (each is a one-liner ;-) ) and put links to them into my start menue. And voilá...I can easily allow / block outgoing connections.
For opening the firewall for outgoing traffic you can simply put
netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound
into a file wich you can name FWallowOUT.cmd for instance. Save this somewhere on you machine and create a link to the file in your start menue. Don't forget to give administrative privileges to it. The same thing you can do for blocking the outgoing traffic again
netsh advfirewall set allprofiles firewallpolicy blockinbound,blockoutbound
Easy and simple. For detailed information about netsh and advfirewall read the man-pages or check Microsofts Technet.

cheers

No comments: