From e4a4c91471d5d5565feeec8846275892689188ee Mon Sep 17 00:00:00 2001 From: lub Date: Sat, 17 Aug 2019 21:30:28 +0200 Subject: [PATCH] add Test-IptablesRule --- expose_forwards.ps1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/expose_forwards.ps1 b/expose_forwards.ps1 index abe56f7..0dd9ff0 100644 --- a/expose_forwards.ps1 +++ b/expose_forwards.ps1 @@ -27,6 +27,31 @@ function Add-IptablesChain { iptables -t $Table -N $Chain } } +function Test-IptablesRule { + param ( + [string]$Chain, + [string]$Table = 'nat', + [array]$Rule + ) + + $argument_list = @( + '-t' + $Table + '-C' + $Chain + )+$Rule + + $check_splat = @{ + FilePath = 'iptables' + ArgumentList = $argument_list + Wait = $true + PassThru = $true + } + + $check = Start-Process @check_splat + + Write-Output ($check.ExitCode -eq 0) +} # setup SWARM-NAT chain $chain = 'SWARM-NAT'