A high-performance, resource-optimized shell script for routers running OpenWrt or pretty much any other linux device.
It executes a network speed test using speedtest-go and sends a detailed, formatted report to a Discord channel via Webhooks.
-
Robust JQ Parsing Now uses
jqfor reliable JSON processing. This ensures that special characters in server names or ISP data don't break the script, while maintaining high performance. -
Advanced Packet Loss Analysis Includes specialized logic to process the relationship between sent and received packets. This ensures high-precision reporting (0.00%) by correctly identifying control packets and data flow.
-
ICMP Precision Uses ICMP ping mode for more accurate latency measurements, avoiding the overhead of HTTP/TCP handshakes.
-
Smart Formatting Reports Download, Upload, Ping (Min/Avg/Max), Jitter, and Packet Loss in a clean, code-blocked Discord message.
Before installing, ensure the following packages are installed on your router:
opkg update
opkg install speedtest-go curl jq
-
Download the script and place
speedtestdiscord.shin the/root/directory. -
Make the script executable:
chmod +x /root/speedtestdiscord.sh
-
Edit the script and configure the following variables:
WEBHOOK_URL– Your Discord Webhook URLFRIENDLY_NAME– Name of your router or location (e.g. Home Router)DISCORD_USER– Username displayed by the Discord bot
To run the speed test automatically every hour, add the following scheduled task via LuCI or crontab -e:
0 * * * * /root/speedtestdiscord.sh
- Security: No use of
eval, eliminating potential shell injection risks. - Reliability: Proper JSON handling regardless of the input data format.
- Efficiency: Data is parsed in a single stream, keeping CPU overhead minimal even on budget routers.
The script is specifically tuned for the speedtest-go implementation, ensuring that unit conversions (Bytes to Mbps) and latency (Nanoseconds to Milliseconds) are calculated with high precision.
This script relies on the excellent speedtest-go tool developed by showwin.
All speed measurement logic is handled by their Go-based Speedtest CLI implementation.
https://github.com/showwin/speedtest-go
Created with a focus on performance, accuracy, and OpenWrt-friendly design.
