2024-01-30

Windows Firewall Block Public InBound 80 Port

Windows Firewall Block Public InBound 80 Port

$FWGroupName = "BlockPublicInBound80Port";

# Remove Rule
$Remove = New-NetFirewallRule -DisplayName "RemovePrepare" -Group $FWGroupName -Direction inbound -Program "C:\windows\system32\calc.exe" -Action Block -RemoteAddress $BlockIPs
Remove-NetFirewallRule -Group $FWGroupName -Confirm:$False

# Add Rule
$BlockIPs = @("0.0.0.1-9.255.255.255", "11.0.0.0-172.15.255.255", "172.32.0.0-192.167.255.255", "192.169.0.0-255.255.255.255")
New-NetFirewallRule -DisplayName "Block 80 Port inBound" -Group $FWGroupName -Direction "inBound" -Protocol "TCP" -LocalPort 80 -Action Block -RemoteAddress $BlockIPs