Created
May 17, 2018 01:09
-
-
Save utarn/ea22e5a1fc2c99372a8f38c2127fff38 to your computer and use it in GitHub Desktop.
Windows Batch Script for Switching between two SSID if one is failed (Change Leelawadee-Secure and TP-Link_OOH)
This file contains 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
@echo off | |
set ipcheck="google.com" | |
set lan_gateway="192.168.2.1" | |
set wlan_gateway="192.168.1.1" | |
set wifi="TP-Link_OOH" | |
echo Check Internet Connection | |
ping -n 1 %ipcheck% | find "TTL" > nul | |
if %errorlevel% == 0 goto finish | |
echo Checking LAN first... | |
netsh wlan disconnect | |
timeout 5 > nul | |
netsh lan reconnect | |
route -p delete 0.0.0.0 > nul | |
route -p add 0.0.0.0 mask 0.0.0.0 %lan_gateway% > nul | |
timeout 5 > nul | |
ping -n 1 %ipcheck% | find "TTL" | |
if %errorlevel% == 1 ( | |
echo %date% %time% LAN failed >> failover.log | |
echo LAN is failed | |
echo Checking %wifi% | |
netsh wlan connect name=%wifi% | |
route -p delete 0.0.0.0 > nul | |
route -p add 0.0.0.0 mask 0.0.0.0 %wlan_gateway% > nul | |
timeout 10 > nul | |
ping -n 1 %ipcheck% | find "TTL" | |
if errorlevel 1 ( | |
echo Not connected! | |
) else ( | |
echo %date% %time% %wifi% is connected >> failover.log | |
echo %wifi% is connected! | |
) | |
) ELSE ( | |
echo %date% %time% LAN is connected >> failover.log | |
echo LAN is connected! | |
) | |
:finish | |
echo %date% %time% Internet is connected. Remain no change. >> failover.log | |
echo Internet is connected. Remain no change. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment