Your cart is currently empty!
Category: ADSL
Advanced ADSL Stability Script: Real-Time CRC Monitoring and Auto-Recovery
For TP-LINK ADSL modems.
If you’re stuck with an ADSL connection, you’ve probably experienced random disconnections, unstable speeds, or the dreaded CRC error spikes that cripple your internet. The worst part? These issues often happen while the connection is technically “up,” but completely unusable.
Instead of manually restarting the modem every time the connection gets unstable, I decided to automate the entire process using a lightweight Bash + Expect script. Now, my modem resets itself when things start to go wrong — and my internet remains stable without me lifting a finger.
What Exactly Did I Build?
- A script that monitors CRC errors in real time by connecting to the modem over Telnet.
- When the number of CRC errors exceeds a configurable threshold (e.g., 100 errors), the script automatically sends a reset command to the modem.
- All actions are logged with timestamps for easy review.
- The script runs continuously and checks the connection every few seconds.
Why Is This Important?
- CRC errors on ADSL lines often don’t increase gradually.
- Instead, the error count can explode into the thousands within minutes, leading to massive packet loss and unusable internet — while your modem still shows as “connected.”
- ISPs usually lock your line speed and don’t dynamically adjust it when signal quality degrades.
- Manual resets become a constant annoyance… unless you automate them.
How Does It Work?
The script uses
expect
to reliably automate Telnet sessions with the modem. It:- Logs into the modem using Telnet.
- Retrieves the current CRC error count.
- If the error count crosses the defined limit, sends the
wan adsl reset
command. - Logs every reset with a timestamp.
The Script
#!/bin/bash MODEM_IP="192.168.1.1" PASSWORD="admin" CRC_LIMIT=100 CHECK_INTERVAL=5 check_crc() { expect -c " set timeout 10 spawn telnet $MODEM_IP expect \"Password:\" { send \"$PASSWORD\r\" } expect \">\" { send \"wan adsl perfdata\r\" } expect \">\" { send \"exit\r\" } expect eof " | grep -i "CRC" | head -n 1 | grep -oE '[0-9]+' } reset_adsl() { expect -c " set timeout 10 spawn telnet $MODEM_IP expect \"Password:\" { send \"$PASSWORD\r\" } expect \">\" { send \"wan adsl reset\r\" } expect \">\" { send \"exit\r\" } expect eof " > /dev/null 2>&1 echo "$(date): ADSL connection reset due to CRC errors!" >> /var/log/adsl_watchdog.log } echo "Started ADSL Watchdog ..." while true; do crc_count=$(check_crc) crc_count=${crc_count:-0} echo "$(date): Trenutni broj CRC grešaka: $crc_count" if [ "$crc_count" -gt "$CRC_LIMIT" ]; then echo "$(date): CRC Threshold reached ($CRC_LIMIT). Resetting connection..." reset_adsl sleep 60 else sleep $CHECK_INTERVAL fi done
I recommend running this on Raspberry pi 🙂