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.
ping output with
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
ping -n 1 %1|Findstr /I /C:"timed out" /C:"host unreachable" /C:"could not find host"
if %errorlevel%==0 set attrib=nonresponsive
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.