nix

Log | Files | Refs | README | LICENSE

iperf-ovh (1544B)


      1 #!/usr/bin/env bash
      2 set -euo pipefail
      3 
      4 SERVER=proof.ovh.net
      5 PORT="" DURATION=10 STREAMS=1 ALL=0 LOGFILE=""
      6 
      7 usage() {
      8 	cat <<EOF
      9 Usage: $0 [-p PORT] [-t SECONDS] [-P STREAMS] [-a] [-l FILE] [-h]
     10 
     11 iperf3 upload/download test against ${SERVER} (ports 5201-5210).
     12 
     13 Options:
     14   -p PORT     test a specific port (default: try 5201-5210 until one works)
     15   -t SECONDS  test duration in seconds (default: ${DURATION})
     16   -P STREAMS  number of parallel streams (default: ${STREAMS})
     17   -a          test all ports 5201-5210
     18   -l FILE     pass --logfile FILE to iperf3 (appends iperf3 output to FILE)
     19   -h          show this help and exit
     20 EOF
     21 }
     22 
     23 [ $# -eq 0 ] && {
     24 	usage
     25 	exit 0
     26 }
     27 
     28 while getopts "p:t:P:al:h" o; do case "$o" in
     29 	p) PORT=$OPTARG ;;
     30 	t) DURATION=$OPTARG ;;
     31 	P) STREAMS=$OPTARG ;;
     32 	a) ALL=1 ;;
     33 	l) LOGFILE=$OPTARG ;;
     34 	h)
     35 		usage
     36 		exit 0
     37 		;;
     38 	*)
     39 		usage >&2
     40 		exit 1
     41 		;;
     42 	esac done
     43 
     44 command -v iperf3 >/dev/null || {
     45 	echo "iperf3 not installed" >&2
     46 	exit 1
     47 }
     48 
     49 LOG=()
     50 [ -n "$LOGFILE" ] && LOG=(--logfile "$LOGFILE")
     51 
     52 test_port() {
     53 	echo "=== ${SERVER}:$1 (${DURATION}s, ${STREAMS} stream) ==="
     54 	iperf3 -c "$SERVER" -p "$1" -t "$DURATION" -P "$STREAMS" "${LOG[@]}" -R || return 1
     55 	iperf3 -c "$SERVER" -p "$1" -t "$DURATION" -P "$STREAMS" "${LOG[@]}"
     56 }
     57 
     58 if [ "$ALL" = 1 ]; then
     59 	for p in $(seq 5201 5210); do test_port "$p" || true; done
     60 elif [ -n "$PORT" ]; then
     61 	test_port "$PORT"
     62 else
     63 	for p in $(seq 5201 5210); do
     64 		test_port "$p" && exit 0
     65 		echo "port $p busy, trying next..." >&2
     66 	done
     67 	echo "all ports busy/unreachable" >&2
     68 	exit 1
     69 fi