From 951c77b9ad78b5578fa7fc78b266b201a4ddc4cc Mon Sep 17 00:00:00 2001 From: Phil Date: Thu, 6 Jul 2023 20:10:58 +0100 Subject: [PATCH] Updated script so it now offers the choice to do specific tests. It also now logs the ISP and the IP address that was tested. --- Linux/speedtest.csv | 2 +- Linux/speedtest.sh | 96 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 87 insertions(+), 11 deletions(-) diff --git a/Linux/speedtest.csv b/Linux/speedtest.csv index 657db49..8ebf716 100644 --- a/Linux/speedtest.csv +++ b/Linux/speedtest.csv @@ -1 +1 @@ -Date,Miles to Server,Download,Upload +Date,ISP,IP,Ping,Download,Upload diff --git a/Linux/speedtest.sh b/Linux/speedtest.sh index 65a6305..62cfa68 100755 --- a/Linux/speedtest.sh +++ b/Linux/speedtest.sh @@ -1,13 +1,29 @@ #!/bin/bash +# Set WAN Number +WAN="WAN 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" +LOG_FILE="PATH TO 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="DISCORD_WEBHOOK_URL" +WEBHOOK_URL="DISCORD WEBHOOK URL" + +# 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 -oE '"organization":\s*"[^"]+"' | grep -oE '"[^"]+"' | tr -d '"') -# Set WAN Number -WAN="NUMBER" # Run the speedtest and parse the output SPEEDTEST=$(speedtest-cli --csv) @@ -31,11 +47,71 @@ fi DOWNLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $DOWNLOAD / (1024*1024) }") UPLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $UPLOAD / (1024*1024) }") -# Append the result to the log file -echo "$(date +"%Y-%m-%d %H:%M:%S"),$PING,$DOWNLOAD_Mbps Mbps,$UPLOAD_Mbps Mbps" >> "$LOG_FILE" +if [ "$log" -eq 1 ]; then + echo "Variable is set to 1. Running command A." -# Prepare the payload for the Discord webhook -PAYLOAD='{"content": "Speedtest Result:\nPing: '"$PING"'\nDownload: '"$DOWNLOAD_Mbps"' Mbps\nUpload: '"$UPLOAD_Mbps"' Mbps"}' + # Append the result to the log file + echo "$(date +"%Y-%m-%d %H:%M:%S"),$ORG,$IP,$PING,$DOWNLOAD_Mbps Mbps,$UPLOAD_Mbps Mbps" >> "$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" <