mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-25 01:13:37 +01:00
51 lines
1.0 KiB
Bash
Executable File
51 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
tool=${1?:"tool argument missing. should be one of iperf3,ping,curl,ab"}
|
|
node=${2?:"node argument missing. should be 'node-1' , 'node-2' etc"}
|
|
shift 2
|
|
|
|
if [[ $node == node-* ]]; then
|
|
index=${node#node-}
|
|
host="10.55.$index.77"
|
|
else
|
|
host=$node
|
|
fi
|
|
|
|
connect_timeout_sec=3
|
|
|
|
function with_set_x() {
|
|
set -x
|
|
"$@"
|
|
{
|
|
ec=$?
|
|
set +x
|
|
return $ec
|
|
} 2>/dev/null
|
|
}
|
|
|
|
case "$tool" in
|
|
ping)
|
|
with_set_x exec ping -W $connect_timeout_sec "$@" "$host"
|
|
;;
|
|
iperf3)
|
|
port=5001
|
|
with_set_x exec iperf3 --client "$host" --port=$port --connect-timeout=$((connect_timeout_sec * 1000)) "$@"
|
|
;;
|
|
curl)
|
|
port=8080
|
|
with_set_x exec curl "http://$host:$port/" -v --connect-timeout $connect_timeout_sec "$@"
|
|
;;
|
|
ab)
|
|
port=8080
|
|
if [[ " $*" != *" -n "* && " $*" != *" -c "* ]]; then
|
|
set -- -n 500 -c 50 "$@"
|
|
fi
|
|
with_set_x exec ab -s $connect_timeout_sec "$@" "http://$host:$port/"
|
|
;;
|
|
*)
|
|
echo "Unknown tool: $tool" >&2
|
|
exit 2
|
|
;;
|
|
esac
|