发现 ICMPv4 入站是否在防火墙上允许。

huangapple go评论58阅读模式
英文:

discovery if ICMPv4 inbound is allowed on firewall

问题

尝试列出 Windows 防火墙上允许的 ICMPv4 入站规则(以便在批处理/PowerShell混合脚本中处理)

powershell.exe "Get-NetFirewallPortFilter -Protocol icmpv4 | Get-NetFirewallRule | ft enabled,direction,action"

这会给我大约10个结果。如何仅筛选具有 "Enabled=True" 和 "Direction=Inbound" 的结果?我可以使用 findstr 来筛选脚本输出,但最好在 PowerShell 中完成这个任务。

英文:

Trying to list ICMPv4 Inbound Allowed rule on windows firewall (to process in batch/ps hybrid script)

powershell.exe "Get-NetFirewallPortFilter -Protocol icmpv4 | Get-NetFirewallRule | ft enabled,direction,action"

This give me about 10 results. How to filter only results which have "Enabled=True" and "Direction=Inbound"? I am able filter script output by findstr, but shoud be better to do this in powershell.

答案1

得分: 1

你应该使用 Where-Object

powershell.exe "Get-NetFirewallPortFilter -Protocol icmpv4 | Get-NetFirewallRule | Where-Object {`$_.Enabled -eq 'True' -and `$_.Direction -eq 'Inbound'} | ft enabled,direction,action"
英文:

You should use Where-Object:

powershell.exe "Get-NetFirewallPortFilter -Protocol icmpv4 | Get-NetFirewallRule | Where-Object {`$_.Enabled -eq 'True' -and `$_.Direction -eq 'Inbound'} | ft enabled,direction,action"

huangapple
  • 本文由 发表于 2023年6月15日 21:35:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483059.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定