2024-07-29 -
This commit is contained in:
parent
3464651970
commit
7ab35bbdef
44
wifi_switch.sh
Executable file
44
wifi_switch.sh
Executable file
@ -0,0 +1,44 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
WIFI_INTERFACE="wlan0"
|
||||||
|
MODEM_INTERFACE="wwan0"
|
||||||
|
CHECK_INTERVAL=10 # Check every 60 seconds
|
||||||
|
|
||||||
|
# Function to check Wi-Fi connection
|
||||||
|
check_wifi() {
|
||||||
|
if iwconfig "$WIFI_INTERFACE" | grep -q "ESSID:off/any"; then
|
||||||
|
return 1 # Wi-Fi is not connected
|
||||||
|
else
|
||||||
|
return 0 # Wi-Fi is connected
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to enable 4G modem
|
||||||
|
enable_4g() {
|
||||||
|
echo "Wi-Fi disconnected. Enabling 4G modem..."
|
||||||
|
sudo ifconfig "$MODEM_INTERFACE" up
|
||||||
|
sudo dhclient "$MODEM_INTERFACE"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to disable 4G modem
|
||||||
|
disable_4g() {
|
||||||
|
echo "Wi-Fi connected. Disabling 4G modem..."
|
||||||
|
sudo ifconfig "$MODEM_INTERFACE" down
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main loop
|
||||||
|
while true; do
|
||||||
|
if check_wifi; then
|
||||||
|
echo "Wi-Fi is connected."
|
||||||
|
if ifconfig "$MODEM_INTERFACE" | grep -q "UP"; then
|
||||||
|
disable_4g
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Wi-Fi is disconnected."
|
||||||
|
if ! ifconfig "$MODEM_INTERFACE" | grep -q "UP"; then
|
||||||
|
enable_4g
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sleep "$CHECK_INTERVAL"
|
||||||
|
done
|
Loading…
Reference in New Issue
Block a user