[Notes] Command Prompt script to check if list of server is pingable

I’m not good in google keyword. This is what i use:

cmd script for ping test to check if server is running

The first link solve my question and is easy to understand
https://superuser.com/questions/1172790/bat-file-to-check-servers-are-up

Original Script (pingtest.bat url.txt)

@echo off
for /f %%a in (%1) do (
    echo Pinging %%a ...
    ping -n 1 %%a | find "Reply" > NUL
    if not errorlevel 1 (echo %%a is up) else (echo %%a is down)
)

What did i change to;
(Run in cmd pingtest2.bat URL.txt)

@echo off
for /f %%a in (%1) do (
REM    echo Pinging %%a ...
    ping -n 1 %%a | find "Reply" > NUL
REM    if not errorlevel 1 (echo %%a is up) else (echo %%a is down)
if not errorlevel 1 (echo %%a,up >> Result.csv) else (echo %%a,down >> Result.csv)
)
echo Test complete

What did it do?
Output the result to Result.csv

Alternative script; it output to file that we specific.

@echo off
REM type nul > %%2
for /f %%a in (%1) do (
REM    echo Pinging %%a ...
    ping -n 1 %%a | find "Reply" > NUL
REM    if not errorlevel 1 (echo %%a is up) else (echo %%a is down)
REM if not errorlevel 1 (echo %%a,up >> Result.csv) else (echo %%a,down >> Result.csv)
if not errorlevel 1 (echo %%a,up >> %2) else (echo %%a,down >> %2)
)
echo Test complete

You Might Also Like

This site uses Akismet to reduce spam. Learn how your comment data is processed.