commit eec831c5605c3becf321793146d0288420218e00 Author: fliegerjohn Date: Tue Aug 22 17:24:54 2023 +0200 Initial commit. diff --git a/checkconnection.sh b/checkconnection.sh new file mode 100755 index 0000000..bb6e3c9 --- /dev/null +++ b/checkconnection.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# +## Variables +# + +# Testsites should return HTTP-Code "204" +testsite1=https://datenkastl.de/.connectivity-check +testsite2=http://captiveportal.kuketz.de + +# Testdomains for ping +testdomain1=datenkastl.de +testdomain2=metager.de + +#Path of curl and ping +curlbin=`type -tp curl` +pingbin=`type -tp ping` + +# +## Functions +# + +# Check connetction with curl +testwithcurl() { + echo "Testing with curl..." + + status=$(curl --write-out "%{http_code}\n" "$testsite1" --output output.txt --silent) + if [[ "$status" = "204" ]]; then + echo "The connection is up!" + + else + + status2=$(curl --write-out "%{http_code}\n" "$testsite2" --output output.txt --silent) + if [[ "$status2" = "204" ]]; then + echo "The network is up, but $testsite1 is down." + + else + echo "The network is down." + fi + fi +} + +#Check connection with ping +testwithping() { + echo "Testing with ping..." + if ping -q -c 1 -W 1 $testdomain1 >/dev/null; then + echo "The connection is up." + + elif ping -q -c 1 -W 1 $testdomain2 >/dev/null; then + echo "The network is up, but $testdomain1 is down." + + else + echo "The network is down." + + fi +} + +# +## Main +# + +# Check for curl and ping and check network + +if [[ -x ${curlbin} ]]; then + testwithcurl + +elif [[ -x ${pingbin} ]]; then + testwithping + +else + echo "Can't find curl or ping. Please install one of them." + exit 1 +fi + + diff --git a/output.txt b/output.txt new file mode 100644 index 0000000..e69de29