Skip to content

Instantly share code, notes, and snippets.

@jazzbanzai
Last active July 15, 2023 14:55
Show Gist options
  • Save jazzbanzai/ada16c08de442aa6a02b5a80370938cc to your computer and use it in GitHub Desktop.
Save jazzbanzai/ada16c08de442aa6a02b5a80370938cc to your computer and use it in GitHub Desktop.
Reboot VirginMedia Super Hub 2
#!/bin/bash
# Create a log file
logfile="/tmp/check_internet.log"
# Get the current time and date
now=$(date)
# Check if wlan0 is up
ifconfig wlan0 | grep -q "inet addr:"
# If wlan0 is up, exit
#if [ $? -eq 0 ]; then
# echo "wlan0 is up" >> $logfile
# exit 0
#fi
# Check if 8.8.8.8 is pingable
ping -I wlan0 -q -i 5 -c 15 8.8.8.8 > /dev/null
# If 8.8.8.8 is pingable, exit
if [ $? -eq 0 ]; then
echo "($now) :: 8.8.8.8 is pingable" >> $logfile
exit 0
fi
# If wlan0 is down or 8.8.8.8 is not pingable, run the script to reboot router
echo "($now) :: wlan0 is down or 8.8.8.8 is not pingable" >> $logfile
sudo /scripts/reboot_virgin2.sh
# Check if internet is working on wlan0
*/15 * * * * sudo /scripts/check_internet.sh
#!/bin/bash
#Tested on - Virgin Super Hub2
# Software Version "V1.01.35"
# Hardware Version 3.11
# Step 1: Get VmLogin.html and extract session cookies
curl -D headers.txt -o login.html http://192.168.0.1/VmLogin.html
cookies=$(grep -oP 'Set-Cookie: \K[^;]+' headers.txt)
# Step 2: Extract the password field name - random each time? for some reason
password_field=$(grep -oP 'name="\K[^"]+(?=" id="password")' login.html)
# Step 3: Authenticate and include session cookies in the request
curl -D headers.txt -b <(echo "$cookies") -d "$password_field=changeme" -o /dev/null -L http://192.168.0.1/cgi-bin/VmLoginCgi
# Step 4: Get VmRgRebootRestoreDevice.html
curl -D headers.txt -b <(grep -oP 'Set-Cookie: \K[^;]+' headers.txt) -o reboot.html http://192.168.0.1/VmRgRebootRestoreDevice.html
value_field=$(grep -oP 'name="\K[^"]+(?=" value="0")' reboot.html)
# Step 5: Submit reboot request and include session cookies
curl -D headers.txt -b <(grep -oP 'Set-Cookie: \K[^;]+' headers.txt) -d "VMRebootResetChangeCache=1&$value_field=0" -o /dev/null -L http://192.168.0.1/cgi-bin/VmRgRebootResetDeviceCfgCgi
# Cleanup: Remove temporary files
rm headers.txt login.html reboot.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment