JSI Tip 7959. How can I send an email if an IP address does NOT respond to a PING?


I have scripted RUThere.bat to send an email to specified users if an IP address that you specify does NOT respond to a PING (Packet InterNet Groper).

The syntax for using RUThere.bat is:

\[call\] RUThere IPAddress Email \[Email2 ... EmailN\]

where IPAdress is the IP address you wish to ping, and EmailN is from 1 through N email addresses to notify.

NOTE: RUThere.bat uses BLAT, the freeware command-line SMTP mailer.

RUThere.bat contains:

@echo off
if \{%2\}

\{\} @echo Syntax: RUThere IPAddress Email \[Email2 ... EmailN\]&exit /b 1 setlocal set IP=%1 set email=%2 set AOK=N call :test If "%AOK%" EQU "Y" goto finish :again shift if \{%2\}

\{\} goto :finish set email=%2 call :quiet>nul 2>&1 goto again :finish if exist "%temp%\RUThere.tmp" del /q "%temp%\RUThere.tmp" endlocal exit /b 0 :test for /f "Tokens=*" %%i in ('@ping -n 1 %IP%^|findstr /i /c:"Reply from"') do ( set AOK=Y ) if "%AOK%" EQU "Y" goto :EOF @echo %IP% does NOT respond.>"%temp%\RUThere.tmp" call :quiet>nul 2>&1 goto :EOF :quiet blat "%temp%\RUThere.tmp" -to %email% -s "%IP% does NOT respond."



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish