added udp/tcp port tests...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2024-01-01 04:15:49 +03:00
parent 692d3aa4fe
commit e62dea61e7
2 changed files with 36 additions and 2 deletions

View File

@ -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://<url>"
echo " https://<url>"
@ -55,6 +56,39 @@ source .pct-helpers
declare -A HANDLERS
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Port
#
# tcp://<addr>:<port>
# udp://<addr>:<port>
#
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

View File

@ -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}