From e62dea61e7c925bbc31646e49f99492c6e5ac7ae Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 1 Jan 2024 04:15:49 +0300 Subject: [PATCH] added udp/tcp port tests... Signed-off-by: Alex A. Naanou --- check-status | 36 +++++++++++++++++++++++++++++++++++- gate-traefik/make.sh | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/check-status b/check-status index 43f06aa..1a52978 100755 --- a/check-status +++ b/check-status @@ -22,6 +22,7 @@ case $1 in echo "Suage:" echo " `basename $0` URL ..." echo + # XXX would be fun to make the docs dynamic... echo "Supported URL formats and schemes:" echo " http://" echo " https://" @@ -55,6 +56,39 @@ source .pct-helpers declare -A HANDLERS +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Port +# +# tcp://: +# udp://: +# + +HANDLERS[tcp]=check-port +HANDLERS[udp]=check-port + +check-port(){ + local udp= + if [[ "${1:0:3}" == "udp" ]] ; then + udp='u' + fi + local target=`sed \ + -e 's/^.*\s*\(tcp\|udp\):\/\///' \ + -e 's/^\s*//;s/\s*$//' \ + <<<$1` + local port=`cut -sd ':' -f 2 <<<$target` + port=${port:=80} + target=`cut -d ':' -f 1 <<<$target` + + local res=$(timeout $TIMEOUT nc -vz${udp} $target $port 2>&1) + + if [[ "$res" =~ .*open$ ]] ; then + echo ERROR + else + echo OK + fi +} + + # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Proxmox lxc # @@ -140,7 +174,7 @@ check-ovpn(){ target=`cut -d ':' -f 1 <<<$target` local res=$(echo -e "\x38\x01\x00\x00\x00\x00\x00\x00\x00" \ - | timeout $TIMEOUT nc -u 46.138.244.248 5555 \ + | timeout $TIMEOUT nc -u $target $port \ | cat -v) if [ -z $res ] ; then diff --git a/gate-traefik/make.sh b/gate-traefik/make.sh index 95f7894..908bb87 100755 --- a/gate-traefik/make.sh +++ b/gate-traefik/make.sh @@ -26,7 +26,7 @@ TMP_PASS_LEN=${TMP_PASS_LEN:=32} DFL_EMAIL=${DFL_EMAIL:=user@example.com} DFL_DOMAIN=${DFL_DOMAIN:=example.com} DFL_ID=${DFL_ID:=500} -DFL_CTHOSTNAME=${DFL_CTHOSTNAME:=gate-test} +DFL_CTHOSTNAME=${DFL_CTHOSTNAME:=gate} DFL_WAN_IP=${DFL_WAN_IP:=192.168.1.101/24} DFL_WAN_GATE=${DFL_WAN_GATE:=192.168.1.252}