檢查 Windows 防火牆是否允許應用程式

檢查 Windows 防火牆是否允許應用程式

太長了;博士使用 Powershell,如何檢查 Windows 防火牆是否允許應用程式?

使用 Windows 10,我想以程式設計方式檢查應用程式是否允許通過 Windows Defender 防火牆。本質上,我想檢查防火牆對話框允許應用程式透過 Windows Defender 防火牆進行通信使用 Powershell。

允許的應用程式

例如,給定一個python.exe安裝在 的程序C:\Program Files\Python\python.exe,我如何檢查是否允許該應用程式與各個網路進行通信領域,私人的,民眾來自 Powershell 腳本?

答案1

幾年前我用過這個: https://medium.com/@glizzykingdreko/open-a-port-on-windows-firewall-with-a-simple-powershell-script-dc5cc48d013a

腳本:

    [int]$port = 3777
)

$ruleName = "Allow Port $port"

# Check if the rule already exists
$existingRule = Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue

if ($existingRule) {
    Write-Host "Firewall rule '$ruleName' already exists."
} else {
    # Create a new inbound rule for the specified port
    New-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Action Allow -Protocol TCP -LocalPort $port
    Write-Host "Firewall rule '$ruleName' created."
}

然後從資料夾執行腳本:.\scriptname.ps1 -port 5000

相關內容