File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed
Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ declare -a ports=(" 4505" " 4506" )
4+ _SETUP_PORTS=False
5+ _TEST_PORTS=False
6+
7+ while getopts " i:st" opt; do
8+ case $opt in
9+ i)
10+ HOST=${OPTARG}
11+ echo " Testing ports on host ${HOST} " >&2
12+ ;;
13+ s)
14+ _SETUP_PORTS=True
15+ echo " Setting up listening ports" >&2
16+ ;;
17+ t)
18+ _TEST_PORTS=True
19+ echo " Testing ports on host ${HOST} " >&2
20+ ;;
21+ \? )
22+ echo " Invalid option: -$OPTARG " >&2
23+ ;;
24+ esac
25+ done
26+
27+ function result {
28+ RESULT=$1
29+ PORT=$2
30+ case $RESULT in
31+ 0)
32+ echo " The access to $PORT was successful"
33+ ;;
34+ 1)
35+ echo " The access to $PORT failed"
36+ exit
37+ ;;
38+ * )
39+ echo " Unknown exit error for the $PORT command. Exiting script."
40+ exit
41+ ;;
42+ esac
43+ }
44+
45+ function test_ports {
46+ for port in " ${ports[@]} " ; do
47+ test_port=$( nc -z ${HOST} ${port} )
48+ rc=$?
49+ result $rc port_${port}
50+ done
51+ }
52+
53+ function start_ports {
54+ for port in ${ports} ; do
55+ test_port=$( nc -lk ${port} & )
56+ done
57+ }
58+
59+ if [ ${_SETUP_PORTS} = True ]; then
60+ start_ports
61+ elif [ ${_TEST_PORTS} = True ]; then
62+ test_ports
63+ fi
You can’t perform that action at this time.
0 commit comments