加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-13 23:56:10 所属栏目: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 interface
在 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帖子

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读