Windows 8.1 How to make Batch Script run a command when it gets a response to ping...

Bob07984

Active Member
Ok so i want a batch file that will run in the background and ping a few servers, and then if it gets a response from any of these servers (If it is able to communicate with them), it executes a command.
It will be running on a machine that in normal operation has no internet (WAN) access, (For security, it doesn't need internet access, just LAN), and i need the batch script to run a command if the machine somehow manages to obtain some sort of internet access. I figured the easiest way would be for it to ping some servers that are unlikely to all be down all at once, (Say, Google.com, microsoft.com, windowsforum.com, for example), however i don't know how to make a batch file run a command if it gets a response.

Any help greatly appreciated...
 

Josephur

Windows Forum Admin
Staff member
Premium Supporter
Microsoft Certified Professional
ping -n 1 your.hostname.here
IF %ERRORLEVEL%==0 (
your_command_here
)

You can also probably loop it like:
:testping
ping -n 1 your.hostname.here
IF NOT %ERRORLEVEL%==0 (
goto testping
)
your_command_here
 
Top