Created
March 20, 2021 20:03
-
-
Save maziara/35de48abda3f39f11f3ddc49fa737b03 to your computer and use it in GitHub Desktop.
A simple batch file to auto-check and auto-connect a VPN connection
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 vpnName="My VPN Connection Name" | |
set pingIp=192.168.1.1 | |
set checkInterval=30 | |
:whileLoop | |
for /f %%i in ('ping %pingIp% -l 1 -n 1 ^| find /c "Reply from %pingIp%"') do SET MATCHES=%%i | |
if %MATCHES%==1 ( | |
rem echo "success" | |
) else ( | |
echo "Target unreachable..." | |
rasdial %vpnName% | |
) | |
ping localhost -n %checkInterval% > nul | |
goto :whileLoop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment