source: tests/nettestlib @ 3b59591

Last change on this file since 3b59591 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#!/bin/bash
2
3
4# IP=IP adress
5# PORT=poort
6# VERIFYPOSITIVE= tekst voor goed resultaat
7# VERIFYNEGATIVE= tekst voor negatief resultaat
8# BODY=input tekst
9nettest()
10{
11        NC=`which nc 2>/dev/null`
12        if ! [ "$NC" ]; then
13                NC=`which netcat`
14        fi
15        if ! [ "$NC" ]; then
16                echo "Netcat is not installed!"
17                exit 1
18        fi     
19       
20        INPUT=/tmp/netinput.$$
21        export OUTPUT=/tmp/netoutput.$$
22       
23        echo "$BODY" > $INPUT || exit 1
24        echo -e "\e[1;32m### nettest: $DESCRIPTION1\e[0m" >&2
25
26        echo "Running nettest on $IP port $PORT:" >&2
27        echo -e "\e[1;30m"
28        $NC -q -1 -v $IP $PORT < $INPUT | tee $OUTPUT || return 1
29        echo -e "\e[0m"
30        rm $INPUT
31       
32        echo "Results: " >&2
33       
34        FAIL=0
35        if [ "$VERIFYNEGATIVE" ]; then
36                if egrep "$VERIFYNEGATIVE" $OUTPUT >&2; then
37                        echo -e "\e[1;31mFAILED: Negative text '$VERIFYNEGATIVE' found!\e[0m" >&2
38                        FAIL=1
39                fi
40        fi
41       
42        if [ "$VERIFYPOSITIVE" ]; then
43                if ! egrep "$VERIFYPOSITIVE" $OUTPUT >&2; then
44                        echo -e "\e[1;31mFAILED: Positive text '$VERIFYPOSITIVE' not found!\e[0m" >&2
45                        FAIL=1
46                fi
47        fi
48       
49        rm $OUTPUT
50       
51        BODY=
52        VERIFYPOSITIVE=
53        VERIFYNEGATIVE=
54        return $FAIL;
55}
56
Note: See TracBrowser for help on using the repository browser.