windows-server-2008 – 如何知道Windows防火墙上当前打开的端口?

Windows XP和 Windows Server 2003上,我可以使用以下命令了解Windows防火墙上当前打开的端口:
netsh firewall show state

但是,在Windows 7和Hyper-V Server 2008 R2上,当我发出该命令时,它会说:

No ports are currently open on all network interfaces.

IMPORTANT: Command executed successfully.
However,“netsh firewall” is deprecated;
use “netsh advfirewall firewall” instead.

显然有端口打开,因为NetBIOS NS,远程桌面和Hyper-V远程管理等服务正在运行.

我尝试了一些’netsh advfirewall’show命令,但没有办法找出Windows防火墙允许哪些端口.

知道当前开放的端口,我可以肯定我允许必要和足够的流量传入,不多也不少.

完成整套高级防火墙规则是非常繁琐且容易出错的.

Windows 7和Windows Server 2008上是否有命令可以有效地执行此操作?

使用相同命令无法获得相同结果的原因是Win7防火墙规则可以特定于单个应用程序,并根据网络类型(专用,域,公共),协议,端口等进行配置.Powershell应该给出您可以更好地查询此信息并对其进行排序.这是一个快速脚本,我需要在需要时转储我的配置.
Function Get-EnabledRules
{
    Param($profile)
    $rules = (New-Object -comObject HNetCfg.FwPolicy2).rules
    $rules = $rules | where-object {$_.Enabled -eq $true}
    $rules = $rules | where-object {$_.Profiles -bAND $profile}
    $rules
}

$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199fdbA5723B}"))
 $connections = $networkListManager.GetNetworkConnections()
[int[] ] $connTypes = @()
$connTypes = ($connections | % {$_.GetNetwork().GetCategory()})
#$connTypes += 1
Write-Host $connTypes

$connTypes | ForEach-Object {Get-EnabledRules -profile $_ | sort localports,Protocol | format-table -wrap -autosize -property Name,@{Label="Action"; expression={$_.action}},@{Label="Protocol"; expression={$_.protocol}},localPorts,applicationname}

其中很多是基于MSDN上的this帖子

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...