
要約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