Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

PingVPNMonitor

PingVPNMonitor.btm

Code:
@echo off
setlocal
REM Use ping interval to keep internet connection alive and to monitor
REM VPN connection status by pinging a VPN host name.  The use of the
REM OSD command requires TCMD and not TCC/LE.  The VPN status is indicated
REM by OSD text during a disconnect and briefly on reconnect.  Also, a
REM message dialog is displayed when a disconnect is first detected.
 
REM The batch file can be started with this command:
REM start /inv %_cmdspec /c C:\PathToBatch\PingVPNMonitor.btm
 
set PingHost=hostname
set PingErr=N
set PingInterval=30
set ErrorText=VPN Not Connected
set OkayText=VPN Connected
set OSDClear=osd /c 2> nul
set OSDError=osd /n /top /hcenter /font=36 /rgb=255,0,0 /time=5 %ErrorText
set OSDOkay=osd /n /top /hcenter /font=36 /rgb=0,255,0 /time=5 %OkayText
set ShowErrDlg=Y
 
REM Deleting the log file will stop the background process in case
REM it needs to be restarted
set LogFile=%@path[%@full[%_batchname]]%@name[%_batchname].log
echo %_date %_time %@name[%_batchname] Started > %LogFile
 
REM wait for VPN connect
do while %@ping[%PingHost,5] LT 0 (delay %PingInterval)
 
echo %_date %_time VPN Connected >> %LogFile
 
REM track VPN disconnect
REM gosubs are separate as the first may change the interval of the second
do forever (gosub TestPing & gosub PingIntervalDelay)
goto end
 
:TestPing
REM Check for shutdown request of deleted log file
if not exist %LogFile exit
set val=%@ping[%PingHost,1]
iff %Val LT 0 then
    REM disconnect detected
    echo %_date %_time Ping response: %Val  --  %ErrorText >> %LogFile
    set PingErr=Y
    set PingInterval=5
    %OSDClear
    %OSDError
    REM Only show dialog on first failure
    iff %ShowErrDlg EQ Y then
        set ShowErrDlg=N
        echo %_date %_time Show error dialog >> %LogFile
        msgbox /t60 /s /m /o OK "Error" Ping response: %Val^N^N%ErrorText
        echo %_date %_time Exit error dialog >> %LogFile
    endiff
elseiff %PingErr EQ Y then
    REM reconnect detected
    echo %_date %_time %OkayText >> %LogFile
    %OSDClear
    %OSDOkay
    set PingErr=N
    set PingInterval=30
    set ShowErrDlg=Y
endiff
return
 
:PingIntervalDelay
delay %PingInterval
return
 
:end

Tim
 
Back
Top
[FOX] Ultimate Translator
Translate