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?
I know this is an old thread, but I wanted to test if a machine was up on my system and unless I have misunderstood, none of the above works if my router reports that an address is unreachable. I am using a batch file rather than a script because I wanted to "KISS" on pretty much any WIN machine. So the approach I used was to do more than one ping and test for "Lost = 0" as follows
I haven't tested this rigorously but so far it does the job for me
The following
checklink.cmd
program 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
Received
with the corresponding keyword in your locale, for examplerecibidos
for 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
ERRORLEVEL
so the equivalent of that second script above becomes:Here's something I found:
Note that
ping 1.1.1.1 -n -w 1000 >NUL
will wait 1 second but only works when connected to a network