I want to continuously ping a server and see a message box when ever it responds i.e. server is currently down. I want to do it through batch file.
I can show a message box as said here Show a popup/message box from a Windows batch file
and can ping continuously by
ping <servername> -t
But how do I check if it responded or not?
The following
checklink.cmdprogram is a good place to start. It relies on the fact that you can do a single-shot ping and that, if successful, the output will contain the line:By extracting tokens 5 and 7 and checking they’re respectively
"Received"and"1,", you can detect the success.Call it with the name (or IP address) you want to test:
Take into account that, if your locale is not English, you must replace
Receivedwith the corresponding keyword in your locale, for examplerecibidosfor Spanish. Do a test ping to discover what keyword is used in your locale.To only notify you when the state changes, you can use:
However, as Gabe points out in a comment, you can just use
ERRORLEVELso the equivalent of that second script above becomes: