From 923a3e2ef11da48073cc7a957833d7448247214d Mon Sep 17 00:00:00 2001 From: Phil Date: Tue, 12 Sep 2023 19:34:37 +0100 Subject: [PATCH] Added new speedtest script for Linux and updated Linux README.md file --- Linux/README.md | 20 +- Linux/iPerf/speedtest.csv | 1 - Linux/iPerf/speedtest.sh | 128 ------------- Linux/speedtest-cli/speedtest.csv | 1 - Linux/speedtest-cli/speedtest.sh | 117 ------------ Linux/speedtest.sh | 306 ++++++++++++++++++++++++++++++ 6 files changed, 317 insertions(+), 256 deletions(-) delete mode 100644 Linux/iPerf/speedtest.csv delete mode 100755 Linux/iPerf/speedtest.sh delete mode 100644 Linux/speedtest-cli/speedtest.csv delete mode 100755 Linux/speedtest-cli/speedtest.sh create mode 100644 Linux/speedtest.sh diff --git a/Linux/README.md b/Linux/README.md index 79b2212..672bc69 100644 --- a/Linux/README.md +++ b/Linux/README.md @@ -1,18 +1,20 @@ # Speedtest_logger -A basic script that uses Speedtest-cli and logs the result to a csv file. - -Within this folder there is 2 different versions of the speedtest script. +A basic script that uses Speedtest-cli and/or iperf3 and logs the result to a csv file, Discord server or InfluDB. -## speedtest-cli -This script uses the speedtest-cli test and requires the following dependencies. -#### Dependencies +## Dependencies + +### speedtest-cli +If you want to use speedtest-cli to test, the following dependencies will be required. + 1) Speedtest CLI: https://www.speedtest.net/apps/cli -## iperf3 -This script uses the iperf3 software and required a iperf3 server ip to be used to test. This version requires the following dependencies. -#### Dependencies +### iperf3 +If you want to use iperf3 to test a, iperf3 server ip will be needed, as well as the following dependencies on the system that will run this script. + 1) iperf3: https://iperf.fr/iperf-download.php 2) jq (lightweight and flexible command-line JSON processor): https://github.com/jqlang/jq + + diff --git a/Linux/iPerf/speedtest.csv b/Linux/iPerf/speedtest.csv deleted file mode 100644 index c242fc1..0000000 --- a/Linux/iPerf/speedtest.csv +++ /dev/null @@ -1 +0,0 @@ -Date,ISP,IP,Download,Upload diff --git a/Linux/iPerf/speedtest.sh b/Linux/iPerf/speedtest.sh deleted file mode 100755 index a8eb77b..0000000 --- a/Linux/iPerf/speedtest.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash - -# Settings -# Set WAN Number -WAN=SET_NUMBER - -# Do you want the script to log to a CSV file? Set log variable to 1 for yes, 0 for no -log=SET_NUMBER - -# Set the path to the log file -LOG_FILE="./speedtest.csv" - -# Do you want the script to output to a Discord webhook? Set discord variable to 1 for yes, 0 for no -discord=SET_NUMBER - -# Set your Discord webhook URL -WEBHOOK_URL="https://DISCORD_WEBHOOK_URL" - -# Set the iPerf3 server IP that you wantr to use -IPERF3_SERVER_IP=SERVER.IP.ADDRESS.HERE - -# The script that will run -# Get IP info -INFO=$(curl -s https://ipv4.am.i.mullvad.net/json | python -m json.tool) - -# Reported IP -IP=$(echo "$INFO" | grep -oE '"ip":\s*"[^"]+"' | grep -oE '[0-9.]+') - -# Reported ISP -ORG=$(echo "$INFO" | grep -oP '(?<="organization": ")[^"]+') - -# Run iperf3 upload and parse the output -IPERF_UP=$(iperf3 -R -c "$IPERF3_SERVER_IP" -J) - -# Check if the iperf3 output is empty or contains errors -if [ -z "$IPERF_UP" ] || [[ "$IPERF_UP" == *"error"* ]]; then - echo "Iperf3 test failed: $IPERF_UP" - exit 1 -fi - -# Run iperf3 and parse the output -IPERF_DOWN=$(iperf3 -c "$IPERF3_SERVER_IP" -J) - -# Check if the iperf3 download output is empty or contains errors -if [ -z "$IPERF_DOWN" ] || [[ "$IPERF_DOWN" == *"error"* ]]; then - echo "Iperf3 test failed: $IPERF_DOWN" - exit 1 -fi -# Extract download and upload speeds from iperf3 output -DOWNLOAD=$(echo "$IPERF_UP" | jq -r '.end.sum_received.bits_per_second') -UPLOAD=$(echo "$IPERF_DOWN" | jq -r '.end.sum_sent.bits_per_second') - -# Convert the download and upload speeds to Mbps -DOWNLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $DOWNLOAD / (1024*1024) }") -UPLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $UPLOAD / (1024*1024) }") - -# Check if the required fields are missing or invalid -if [ -z "$DOWNLOAD_Mbps" ] || [ -z "$UPLOAD_Mbps" ]; then - echo "Missing or invalid iperf3 fields: DOWNLOAD=$DOWNLOAD_Mbps, UPLOAD=$UPLOAD_Mbps" - exit 1 -fi - -if [ "$log" -eq 1 ]; then - echo "Log Variable is set to 1. Writing to log." - - # Append the result to the log file - echo "$(date +"%Y-%m-%d %H:%M:%S"),$IPERF3_SERVER_IP,$ORG,$IP,$DOWNLOAD_Mbps Mbps,$UPLOAD_Mbps Mbps" >> "$LOG_FILE" - -# Check if the variable is set to 0 -elif [ "$log" -eq 0 ]; then - echo "Log Variable is set to 0. Skipping log to file" - -# Variable is not set to 1 or 0 -else - echo "Discord Variable is not set to a valid value." -fi - -if [ "$discord" -eq 1 ]; then - echo "Discord Variable is set to 1. Sending to Discord" - - # Prepare the payload for the Discord webhook - curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <> "$LOG_FILE" - -# Check if the variable is set to 0 -elif [ "$log" -eq 0 ]; then - echo "Skipping log to file" - -# Variable is not set to 1 or 0 -else - echo "Variable is not set to a valid value." -fi - -if [ "$discord" -eq 1 ]; then - echo "Variable is set to 1." - - # Prepare the payload for the Discord webhook -curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <> "$LOG_FILE" + +# Check if the variable is set to 0 +elif [ "$log" -eq 0 ]; then + echo "Log Variable is set to 0. Skipping log to file" + +# Variable is not set to 1 or 0 +else + echo "DISCORD Variable is not set to a valid value." +fi + +# Do you want the script to output to a DISCORD webhook? +if [ "$DISCORD" -eq 1 ]; then + echo "DISCORD Variable is set to 1. Sending to DISCORD" + + # Prepare the payload for the DISCORD webhook + curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <> "$LOG_FILE" + +# Check if the variable is set to 0 +elif [ "$log" -eq 0 ]; then + echo "Skipping log to file" + +# Variable is not set to 1 or 0 +else + echo "Log to File Variable is not set to a valid value." +fi + +if [ "$DISCORD" -eq 1 ]; then + echo "DISCORD Variable is set to 1." + +# Prepare the payload for the Discord webhook +curl -H "Content-Type: application/json" -X POST --data @- "$WEBHOOK_URL" <