如何从防火墙规则中获取IP地址列表?

问题描述 投票:0回答:2

我正在尝试从某个防火墙规则获取当前配置的 IP 地址列表,以便我可以将其与地址列表进行比较,以添加和删除已存在的地址。

使用here找到的语法,我可以显示规则中的前几个IP地址:

$Rule = Get-NetFirewallRule -Action Block -Enabled True -Direction Inbound
$Rule | Format-Table -Property DisplayName,@{Name='RemoteAddress';Expression={($PSItem | Get-NetFirewallAddressFilter).RemoteAddress}}

输出:

DisplayName                     RemoteAddress
-----------                     -------------
Block SMTP Brute Force (TCP-In) {5.34.207.103, 103.145.254.105, 46.148.40.171, 80.94.95.206...}

这表明我确实能够访问该列表,但它并没有真正允许我枚举它。

如何将此列表放入运行时变量中进行处理?

powershell windows-firewall
2个回答
0
投票

我能够通过稍微改变语法来实现这一点:

$Rules = Get-NetFirewallRule -Action Block -Enabled True -Direction Inbound
$Rules | % { 
  $Rule = $_
  $List = ($Rule | Get-NetFirewallAddressFilter).RemoteAddress
  Write-Output $Rule.DisplayName
  Write-Output "----------------"
  Write-Output $List
  Write-Output ""
}

0
投票

(Get-NetFirewallRule |Where-Object { $_.DisplayName -eq 'RULE_NAME' } | Get-NetFirewallAddressFilter).RemoteAddress

© www.soinside.com 2019 - 2024. All rights reserved.