Comment
Author: Admin | 2025-04-28
1 putty is running that is connected to the remote servernetstat.exe -n -a -o -p TCP | FIND ":%_PPORT%" | FIND /C ":%_PPORT%" | FIND "1" >nul 2>&1IF ERRORLEVEL 1 ( tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq putty.exe" 2>nul | FIND /C "Running" | FIND "1" >nul 2>&1 IF ERRORLEVEL 1 ( REM kill all running puttys (owned by system) FOR /F "usebackq tokens=2 skip=2" %%p IN (`tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq putty.exe"`) DO taskkill.exe /F /PID %%p /T >nul 2>&1 CALL :RESTARTPLINK "EXTRA PUTTY FOUND" ))EXIT /BREM =======================================================================================REM = PINGCHECK - PING address to make sure it is reachableREM =======================================================================================:PINGCHECKPING %~1 -n 1 -w 5000 | FIND "TTL=" >nul 2>&1IF ERRORLEVEL 1 ( PING google.com -n 1 -w 500 | FIND "TTL=" >nul 2>&1 IF ERRORLEVEL 1 ( CALL :SPEAK "CHECK INTERNET CONNECTION" && SLEEP 60 ) PING google.com -n 1 -w 5000 | FIND "TTL=" >nul 2>&1 IF ERRORLEVEL 1 ( CALL :SPEAK "CHECK INTERNET CONNECTION" && SLEEP 60 ) PING google.com -n 1 -w 5000 | FIND "TTL=" >nul 2>&1 IF ERRORLEVEL 1 ( CALL :SPEAK "KILL SOCKS PROGRAMS" SLEEP 100 pskill.exe -t putty >nul 2>&1 pskill.exe -t thunderbird >nul 2>&1 pskill.exe -t ThunderbirdPortable >nul 2>&1 ))EXIT /BREM =======================================================================================REM = KILLDUPES - kills duplicate processes, except for the one with lowest pidREM =======================================================================================:KILLDUPESREM Check that more than 1 process is runningtasklist.exe /V /NH /FI "IMAGENAME eq %~1" /FI "USERNAME eq SYSTEM" 2>nul | FIND /C "K Running" | FIND "1" >nul 2>&1IF NOT ERRORLEVEL 1 EXIT /BREM Create Filename in current dir (of this script)SET _T=%TIME: =0%&&SET _T=!_T::=-!&&SET _T=%~dp0%!_T:~0,-2!logREM Create the file in the same dir as this script named for date and sorted by PIDtasklist.exe /V /NH /FI "IMAGENAME eq %~1" /FI "USERNAME eq SYSTEM" 2>nul | SORT /+29 > "%_T%"REM Check that the file was created or exitIF NOT EXIST "%_T%" ( CALL :SPEAK "FILE CREATION FAILED" && EXIT /B )REM kill all the processes found except for 1, do not kill the process with the lowest pid numberFOR /F "tokens=2 skip=2" %%p IN (%_T%) DO taskkill.exe /F /PID %%p /TREM erase the fileREM ERASE /Q "%_T%" >nul 2>&1REM check that the file was erasedREM IF EXIST "%_T%" ( CALL :SPEAK "ERASE FILE FAILED" && EXIT /B )EXIT /BREM =======================================================================================REM = CREATEATJOB - runs job (START this file) every 5 minutesREM =======================================================================================:CREATEATJOB:: delete all putty AT jobsAT | FIND /C
Add Comment