#!/bin/bash # IP=IP adress # PORT=poort # VERIFYPOSITIVE= tekst voor goed resultaat # VERIFYNEGATIVE= tekst voor negatief resultaat # BODY=input tekst nettest() { NC=`which nc 2>/dev/null` if ! [ "$NC" ]; then NC=`which netcat` fi if ! [ "$NC" ]; then echo "Netcat is not installed!" exit 1 fi INPUT=/tmp/netinput.$$ export OUTPUT=/tmp/netoutput.$$ echo "$BODY" > $INPUT || exit 1 echo -e "\e[1;32m### nettest: $DESCRIPTION1\e[0m" >&2 echo "Running nettest on $IP port $PORT:" >&2 echo -e "\e[1;30m" $NC -q -1 -v $IP $PORT < $INPUT | tee $OUTPUT || return 1 echo -e "\e[0m" rm $INPUT echo "Results: " >&2 FAIL=0 if [ "$VERIFYNEGATIVE" ]; then if egrep "$VERIFYNEGATIVE" $OUTPUT >&2; then echo -e "\e[1;31mFAILED: Negative text '$VERIFYNEGATIVE' found!\e[0m" >&2 FAIL=1 fi fi if [ "$VERIFYPOSITIVE" ]; then if ! egrep "$VERIFYPOSITIVE" $OUTPUT >&2; then echo -e "\e[1;31mFAILED: Positive text '$VERIFYPOSITIVE' not found!\e[0m" >&2 FAIL=1 fi fi rm $OUTPUT BODY= VERIFYPOSITIVE= VERIFYNEGATIVE= return $FAIL; }