Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

From a Windows 7 machine, I ping an IP address of a turned-off machine.

Pinging with 32 bytes of data:
Reply from Destination host unreachable.
Reply from Destination host unreachable. 
Reply from Destination host unreachable.

Ping statistics for
    Packets: Sent = 3, Received = 3, Lost = 0 (0% loss)

Even though there is no reply, the errorlevel is set to 0.

What I am trying to do, is figure out if a remote machine is replying to ping. One of my tests is to turn off the machine and ping it. For some reason, ping sets errorlevel to 0.

share|improve this question
add comment

2 Answers 2

This is because the destination is on your local subnet. If the destination is outside your local subnet, the expected Request timed out. is seen. However, even non-existent destinations within your local subnet will report Reply from x.x.x.x: Destination host unreachable.. As this whirlpool post explains it, it all depends on whether its the first hop that timed out - and pinging your local subnet is only a single hop. Apparently, it's by design that the errorlevel is set to 0 when any reply is received, and a host unreachable counts as a reply.


Parsing ping output with findstr

Source: http://forums.techguy.org/7318331-post3.html

The following will ping it once (ping -n 1). The %1 is the first param passed to the batch file. The variable attrib is set depending on whether the destination replies or not.

echo Scanning %1
set attrib=responding
ping -n 1 %1|Findstr /I /C:"timed out" /C:"host unreachable" /C:"could not find host"
if %errorlevel%==0 set attrib=nonresponsive

Separate utility

There's an interesting utility called alive. I haven't tried it, and it was released in 2002, so it may not even work in Windows 7. However, if it does work, it will set the errorlevel to 2 when the destination host is unreachable. I wouldn't really recommend this, though.

share|improve this answer
+1 for alive, used that many years ago too, for this very reason. –  Bryan Mar 29 '12 at 7:08
If the response is "Ping request could not find host madeup04. Please check the name and try again" this does not work, because it is looking for "host unreachable", so your result is "madeup04 is responding" which is wrong. –  James Jenkins May 1 at 13:02
@JamesJenkins I did make the assumption that, as in the question, the ping attempt is against an IP address. Even then, it's a trivial change (add another /C search string). Hardly worth a downvote. As it is, I have amended the answer, so thanks for pointing that out. –  Bob May 1 at 13:29
add comment

This works for me on Windows 7:

@echo off
setlocal enableextensions enabledelayedexpansion

for /f %%i in (PCS.TXT) do (
   ping -n 2 %%i |find "TTL=" && SET bHOSTUP=1
   IF !bHOSTUP! equ 1 (
      CALL :HOSTUP %%i
   ) else (
      CALL :HOSTDOWN %%i 

echo Host UP %1

echo Host DOWN %1

exit /B
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.