简体   繁体   English

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

[英]How to get the list of IP addresses from a firewall rule?

I'm trying to get the current list of configured IP addresses from a certain firewall rule, so that I can compare it to a list of addresses to add and eliminate the ones that already exist.我正在尝试从某个防火墙规则中获取当前配置的 IP 地址列表,以便我可以将其与地址列表进行比较以添加和删除已经存在的地址。

Using the syntax found here , I'm able to display the first few IP addresses from the rule:使用此处找到的语法,我能够显示规则中的前几个 IP 地址:

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

Output: Output:

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

This shows that I have indeed been able to access the list, but it stops short of actually allowing me to enumerate it.这表明我确实能够访问该列表,但实际上并不能让我枚举它。

How can I get this list into a runtime variable for processing?如何将此列表放入运行时变量中进行处理?

I was able to accomplish this by altering the syntax slightly:我能够通过稍微更改语法来完成此操作:

$Rule = Get-NetFirewallRule -Action Block -Enabled True -Direction Inbound
$List = ($Rule | Get-NetFirewallAddressFilter).RemoteAddress
$List

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM