Skip to content

Instantly share code, notes, and snippets.

@maziara
Created March 20, 2021 20:03
Show Gist options
  • Save maziara/35de48abda3f39f11f3ddc49fa737b03 to your computer and use it in GitHub Desktop.
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
@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