@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET IP[1]=203.158.101.100=user_xx@gmail.com
SET IP[2]=8.8.8.8=user_xx@gmail.com
SET TimeBetweenPings=5
SET RetryBeforeEmail=5
REM SETTING FLAGS
FOR /F "tokens=2 delims==" %%A IN ('SET IP[') DO (
SET AlertFlag[%%A]=0
SET AlertSentGood[%%A]=1
)
:Home
CLS
REM PINGING DESTINATIONS
ECHO ERR EML TARGET IP ADDRESS
ECHO -------------------------
FOR /F "tokens=2,3 delims==" %%A IN ('SET IP[') DO (
ECHO [!AlertFlag[%%A]!] [!AlertSentGood[%%A]!] [%%A]
PING -n 1 %%A >NUL
IF !errorlevel! == 0 (
SET AlertFlag[%%A]=0
IF "!AlertSentGood[%%A]!" == "0" (
CALL :EMAIL "%%A Resolved" "%%B"
SET AlertSentGood[%%A]=1
)
) ELSE (
SET /a AlertFlag[%%A]+=1
)
IF !AlertFlag[%%A]! == %RetryBeforeEmail% (
CALL :EMAIL "%%A ERROR ALERT" "%%B"
SET AlertSentGood[%%A]=0
)
)
PING -n %TimeBetweenPings% -w 1000 10.0.0.0>NUL
Goto Home
:EMAIL
ECHO SENDING EMAIL
REM PUT BLAT COMMAND HERE
EXIT /b
รบกวนผู้รู้ช่วยด้วยครับ ตามนี้เลยครับ คืออยากรู้ไปศึกษาต่อครับ ขอบคุณล่วงหน้าครับ
ช่วยอธิบายโค๊ดนี้ให้หน่อยคับ
SETLOCAL EnableDelayedExpansion
SET IP[1]=203.158.101.100=user_xx@gmail.com
SET IP[2]=8.8.8.8=user_xx@gmail.com
SET TimeBetweenPings=5
SET RetryBeforeEmail=5
REM SETTING FLAGS
FOR /F "tokens=2 delims==" %%A IN ('SET IP[') DO (
SET AlertFlag[%%A]=0
SET AlertSentGood[%%A]=1
)
:Home
CLS
REM PINGING DESTINATIONS
ECHO ERR EML TARGET IP ADDRESS
ECHO -------------------------
FOR /F "tokens=2,3 delims==" %%A IN ('SET IP[') DO (
ECHO [!AlertFlag[%%A]!] [!AlertSentGood[%%A]!] [%%A]
PING -n 1 %%A >NUL
IF !errorlevel! == 0 (
SET AlertFlag[%%A]=0
IF "!AlertSentGood[%%A]!" == "0" (
CALL :EMAIL "%%A Resolved" "%%B"
SET AlertSentGood[%%A]=1
)
) ELSE (
SET /a AlertFlag[%%A]+=1
)
IF !AlertFlag[%%A]! == %RetryBeforeEmail% (
CALL :EMAIL "%%A ERROR ALERT" "%%B"
SET AlertSentGood[%%A]=0
)
)
PING -n %TimeBetweenPings% -w 1000 10.0.0.0>NUL
Goto Home
:EMAIL
ECHO SENDING EMAIL
REM PUT BLAT COMMAND HERE
EXIT /b
รบกวนผู้รู้ช่วยด้วยครับ ตามนี้เลยครับ คืออยากรู้ไปศึกษาต่อครับ ขอบคุณล่วงหน้าครับ