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.
This commit is contained in:
parent
16ecb9aae5
commit
951c77b9ad
@ -1 +1 @@
|
||||
Date,Miles to Server,Download,Upload
|
||||
Date,ISP,IP,Ping,Download,Upload
|
||||
|
||||
|
@ -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" <<EOF
|
||||
{
|
||||
"content": null,
|
||||
"embeds": [
|
||||
{
|
||||
"title": "Speedtest Result - WAN $WAN",
|
||||
"color": 5814783,
|
||||
"fields": [
|
||||
{
|
||||
"name": "Time:",
|
||||
"value": "$(date +'%Y-%m-%d %H:%M:%S')"
|
||||
},
|
||||
{
|
||||
"name": "ISP:",
|
||||
"value": "$ORG"
|
||||
},
|
||||
{
|
||||
"name": "IP:",
|
||||
"value": "$IP"
|
||||
},
|
||||
{
|
||||
"name": "Ping:",
|
||||
"value": "$PING ms"
|
||||
},
|
||||
{
|
||||
"name": "Download:",
|
||||
"value": "$DOWNLOAD_Mbps mbps"
|
||||
},
|
||||
{
|
||||
"name": "Upload:",
|
||||
"value": "$UPLOAD_Mbps mbps"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"attachments": []
|
||||
}
|
||||
EOF
|
||||
|
||||
|
||||
# Check if the variable is set to 0
|
||||
elif [ "$discord" -eq 0 ]; then
|
||||
echo "Skipping send to Discord"
|
||||
|
||||
# Variable is not set to 1 or 0
|
||||
else
|
||||
echo "Variable is not set to a valid value."
|
||||
fi
|
||||
|
||||
# Send the payload to the Discord webhook - If you dont want this, comment out this command
|
||||
curl -H "Content-Type: application/json" -X POST --data "{\"content\": null, \"embeds\": [{\"title\": \"Speedtest Result - WAN $WAN\", \"description\": \"Time: $(date +"%Y-%m-%d %H:%M:%S")\nPing: $PING ms\nDownload: $DOWNLOAD_Mbps mbps\nUpload: $UPLOAD_Mbps mbps\", \"color\": 5814783}], \"attachments\": []}" $WEBHOOK_URL
|
||||
|
||||
Loading…
Reference in New Issue
Block a user