iperf-mine (1593B)
1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 SERVER=speedtest.lu.buyvm.net 5 PORT="5201" DURATION=60 STREAMS=5 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 echo "[download]" 55 iperf3 -c "$SERVER" -p "$1" -t "$DURATION" -P "$STREAMS" "${LOG[@]}" -R || return 1 56 echo "[upload]" 57 iperf3 -c "$SERVER" -p "$1" -t "$DURATION" -P "$STREAMS" "${LOG[@]}" 58 } 59 60 if [ "$ALL" = 1 ]; then 61 for p in $(seq 5201 5210); do test_port "$p" || true; done 62 elif [ -n "$PORT" ]; then 63 test_port "$PORT" 64 else 65 for p in $(seq 5201 5210); do 66 test_port "$p" && exit 0 67 echo "port $p busy, trying next..." >&2 68 done 69 echo "all ports busy/unreachable" >&2 70 exit 1 71 fi