| Server IP : 68.178.202.69 / Your IP : 216.73.216.143 Web Server : Apache System : Linux 69.202.178.68.host.secureserver.net 3.10.0-1160.139.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Nov 3 13:30:41 UTC 2025 x86_64 User : ikioworld ( 1005) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/opt/nydus/ops/customer_local_ops/operating_system/powershell/ |
Upload File : |
param([Parameter(Mandatory)] [Int] $port,
[Parameter(Mandatory)] [String] $action)
function Ensure-NetFirewallRule {
param($displayName, $direction, $action, $protocol, $localPort)
if(Get-NetFirewallRule -DisplayName $displayName -ea SilentlyContinue){
Remove-NetFirewallRule -DisplayName $displayName
}
New-NetFirewallRule -DisplayName $displayName -Direction $direction -Action $action -Protocol $protocol -LocalPort $localPort
}
if ($action -eq "open") {
"Configuring firewall to open port $port"
$ruleName = "Open TCP $port"
Ensure-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Action Allow -Protocol TCP -LocalPort $port
netsh advfirewall firewall set rule name=$ruleName new localport=$port
# Remove any blocks. NOTE: The spaces in the rule names are required. That's how
# the rules were created by OH for the images, so need to keep them consistent.
Remove-NetFirewallRule -DisplayName "Block TCP $port " -ea SilentlyContinue
} elseif ($action -eq "close") {
"Configuring firewall to close port $port"
# Remove instances of the open port.
Remove-NetFirewallRule -DisplayName "Open TCP $port" -ea SilentlyContinue
# Block the port
$ruleName = "Block TCP $port "
Ensure-NetFirewallRule -DisplayName $ruleName -Direction Inbound -Action Block -Protocol TCP -LocalPort $port
netsh advfirewall firewall set rule name=$ruleName new localport=$port
} else {
"Unknown action $action"
exit 1
}