Last active
November 25, 2023 09:56
-
-
Save QNimbus/f6048a556b93fcf10eb2a70d5be1a016 to your computer and use it in GitHub Desktop.
Basic network performance testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
# Function to check if a command exists | |
command_exists() { | |
command -v "$1" >/dev/null 2>&1 | |
} | |
# Function to perform iperf test | |
run_iperf_test() { | |
if ! command_exists iperf3; then | |
echo "iperf3 is not installed. Install it using 'sudo apt-get install iperf3' on Ubuntu or 'pkg install iperf3' on FreeBSD." | |
exit 1 | |
fi | |
iperf_server_ip=$1 | |
iperf_port=$2 | |
echo "Running iperf test..." | |
if iperf3 -c "$iperf_server_ip" -p "$iperf_port" -t 10; then | |
echo "Iperf test completed successfully." | |
else | |
echo "Iperf test failed." | |
fi | |
} | |
# Function to test SMB file transfer | |
test_smb_transfer() { | |
if ! command_exists smbclient; then | |
echo "smbclient is not installed. Install it using 'sudo apt-get install smbclient' on Ubuntu or 'pkg install samba412' on FreeBSD." | |
exit 1 | |
fi | |
smb_server_ip=$1 | |
smb_share_name=$2 | |
smb_username=$3 | |
smb_password=$4 | |
echo "Testing SMB file transfer..." | |
if smbclient "//$smb_server_ip/$smb_share_name" -c 'get testfile' -U "$smb_username%$smb_password"; then | |
echo "SMB file transfer test completed successfully." | |
else | |
echo "SMB file transfer test failed." | |
fi | |
} | |
# Function to test rsync file transfer | |
test_rsync_transfer() { | |
if ! command_exists rsync; then | |
echo "rsync is not installed. Install it using 'sudo apt-get install rsync' on Ubuntu or 'pkg install rsync' on FreeBSD." | |
exit 1 | |
fi | |
rsync_source_path=$1 | |
rsync_destination_path=$2 | |
echo "Testing rsync file transfer..." | |
if rsync -avzh --progress "$rsync_source_path" "$rsync_destination_path"; then | |
echo "Rsync file transfer test completed successfully." | |
else | |
echo "Rsync file transfer test failed." | |
fi | |
} | |
# Main script | |
is_freebsd=$(uname | grep -o FreeBSD) | |
is_ubuntu=$(grep -o Ubuntu /etc/os-release | head -n 1) | |
is_wsl=$(uname -r | grep -e Microsoft -e WSL) | |
if [ "$is_freebsd" != "FreeBSD" ] && [ "$is_ubuntu" != "Ubuntu" ] && [ -z "$is_wsl" ]; then | |
echo "This script is intended to run on FreeBSD, Ubuntu, or Ubuntu on WSL2." | |
exit 1 | |
fi | |
mode=$1 | |
shift | |
case $mode in | |
iperf) | |
if [ $# -eq 2 ]; then | |
run_iperf_test "$@" | |
else | |
echo "Usage: $0 iperf <iperf_server_ip> <iperf_port>" | |
exit 1 | |
fi | |
;; | |
smb) | |
if [ $# -eq 4 ]; then | |
test_smb_transfer "$@" | |
else | |
echo "Usage: $0 smb <smb_server_ip> <smb_share_name> <smb_username> <smb_password>" | |
exit 1 | |
fi | |
;; | |
rsync) | |
if [ $# -eq 2 ]; then | |
test_rsync_transfer "$@" | |
else | |
echo "Usage: $0 rsync <rsync_source_path> <rsync_destination_path>" | |
exit 1 | |
fi | |
;; | |
*) | |
echo "Invalid mode. Available modes: iperf, smb, rsync" | |
exit 1 | |
;; | |
esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
# Function to start iperf in server mode | |
start_iperf_server() { | |
echo "Starting iperf3 server..." | |
iperf3 -s | |
} | |
# Check if the script is running on a supported OS | |
if [ "$(uname)" = "FreeBSD" ] || [ "$(grep -o Ubuntu /etc/os-release)" = "Ubuntu" ]; then | |
start_iperf_server | |
else | |
echo "This script is intended to run on FreeBSD or Ubuntu." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment