Skip to content

Instantly share code, notes, and snippets.

@rany2
Created January 14, 2024 16:58
Show Gist options
  • Save rany2/a13e84902a114cb0f7bc09b54435e8b2 to your computer and use it in GitHub Desktop.
Save rany2/a13e84902a114cb0f7bc09b54435e8b2 to your computer and use it in GitHub Desktop.
IPERF3 script
#!/bin/sh
# Generate a random 32-bit number to use to pick a random
# IPERF3 port. Random device is overridable by setting the
# RAND_DEVICE environment variable.
RAND_DEVICE=${RAND_DEVICE:-/dev/random}
RAND_NUMBER=$(hexdump -n4 -e '4/4 "%u"' "${RAND_DEVICE}")
# IPERF3 paramaters, only dynamic parameter is IPERF3_PORT.
IPERF3_BIN=${IPERF3_BIN:-iperf3}
IPERF3_HOSTNAME=${IPERF3_HOSTNAME:-gw}
IPERF3_MIN_PORT=${IPERF3_MIN_PORT:-9200}
IPERF3_MAX_PORT=${IPERF3_MAX_PORT:-9240}
IPERF3_PORT=$((IPERF3_MIN_PORT + RAND_NUMBER % (IPERF3_MAX_PORT-IPERF3_MIN_PORT+1)))
# Show final command by setting "set -x" and run it via exec.
set -x
exec -- "${IPERF3_BIN}" -c"${IPERF3_HOSTNAME}" -p"${IPERF3_PORT}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment