How to know currently open ports on the Windows Firewall?
On Windows XP and Windows Server 2003, I can know currently open ports on the Windows Firewall using the following
command:
netsh firewall show state
However, on Windows 7 and Hyper-V Server 2008 R2, when I give that command, it says:
No ports are currently open on all network interfaces.
IMPORTANT: Command executed successfully.
However, "netsh firewall" is deprecated;
use "netsh advfirewall firewall" instead.
Apparently there are ports open because services such as NetBIOS NS, Remote Desktop, and Hyper-V remote administration
are functioning.
I tried a few 'netsh advfirewall' show commands, but didn't get a way to find out which ports are permit by Windows Firewall.
Knowing the currently open ports, I can be sure that I'm permitting necessary and sufficient traffic to pass in, no more,
no less.
Going through the whole set of advanced firewall rules is so tedious and error-prone.
Is there a command on Windows 7 and Windows Server 2008 to do this efficiently?
January 12th, 2011 8:05am
I'm not sure if you wanted something like that but it shows you all rules and each rule is detailed
netsh advfirewall firewall show rule name=all verbose
you can of course filter rule names and profiles (see help on netsh advfirewall show rule ?)Regards, Krzysztof
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2011 8:55am
Thanks for this suggestion.
However, there are usually a lot of rules and I didn't find a command to filter active ones.
GUI can be unavailable on Server Core.
I think it would be better if we could find out effective open ports using a single command.
January 12th, 2011 9:28am
You could write PowerShell script for this - look https://msmvps.com/blogs/richardsiddaway/archive/2009/08/30/enable-ping.aspx and http://blogs.technet.com/b/jamesone/archive/2009/02/18/how-to-manage-the-windows-firewall-settings-with-powershell.aspx
i.e. simple variation on first link
$fw = New-Object -ComObject HNetCfg.FWPolicy2
$fw.Rules | where {$_.Enabled -like $true} | Format-Table LocalPorts
Free Windows Admin Tool Kit Click here and download it now
January 12th, 2011 4:42pm
Hi,
You can use PORTQRY tool to identify the port status.
Below is a link to download the PORTQRY tool
http://www.microsoft.com/downloads/details.aspx?familyid=89811747-C74B-4638-A2D5-AC828BDC6983&displaylang=en
Below is an article about the PORTTQRY tool
http://support.microsoft.com/?kbid=310099
Thanks.
January 12th, 2011 5:00pm
Thanks, Olexandr! It works. I'd like to recommend another answer on Server Fault:
http://serverfault.com/questions/221075/how-to-know-currently-open-ports-on-the-windows-firewall/221807#221807
Free Windows Admin Tool Kit Click here and download it now
January 13th, 2011 2:13am