Created
February 10, 2025 15:35
-
-
Save Snuupy/50faadea20f5c0fce27c9a537c95205e to your computer and use it in GitHub Desktop.
Rogers coax DHCP is broken on DOCSIS 3.1 zzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Interface to monitor | |
WAN_INTERFACE="wan" | |
FAIL_COUNT=0 | |
MAX_FAILS=3 | |
PING_HOST_1="1.1.1.1" | |
PING_HOST_2="8.8.8.8" | |
# Lock file path | |
LOCK_FILE="/tmp/check_wan.lock" | |
# Function to remove the lock file when the script exits | |
cleanup() { | |
rm -f $LOCK_FILE | |
} | |
trap cleanup EXIT | |
# Check if another instance of the script is already running | |
if [ -f "$LOCK_FILE" ]; then | |
echo "Script is already running. Exiting." | |
exit 1 | |
fi | |
# Create the lock file | |
touch $LOCK_FILE | |
# Function to ping a host | |
ping_host() { | |
local host=$1 | |
ping -c 1 -W 5 $host > /dev/null 2>&1 | |
return $? | |
} | |
# Step 1: Try pinging 1.1.1.1 (Cloudflare DNS) | |
while [ $FAIL_COUNT -lt $MAX_FAILS ]; do | |
ping_host $PING_HOST_1 | |
if [ $? -eq 0 ]; then | |
echo "$PING_HOST_1 is reachable. WAN is up." | |
exit 0 | |
else | |
echo "Failed to ping $PING_HOST_1. Fail count: $FAIL_COUNT" | |
FAIL_COUNT=$((FAIL_COUNT+1)) | |
sleep 60 # Wait 60 seconds before retrying | |
fi | |
done | |
# Step 2: If 1.1.1.1 fails, try pinging 8.8.8.8 (Google DNS) | |
FAIL_COUNT=0 | |
while [ $FAIL_COUNT -lt 2 ]; do | |
ping_host $PING_HOST_2 | |
if [ $? -eq 0 ]; then | |
echo "$PING_HOST_2 is reachable. WAN is up." | |
exit 0 | |
else | |
echo "Failed to ping $PING_HOST_2. Fail count: $FAIL_COUNT" | |
FAIL_COUNT=$((FAIL_COUNT+1)) | |
sleep 60 # Wait 60 seconds before retrying | |
fi | |
done | |
# Step 3: If both hosts fail, bring up the WAN interface | |
echo "Both $PING_HOST_1 and $PING_HOST_2 are unreachable. Bringing up the WAN interface." | |
ifup $WAN_INTERFACE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment