The question pointed by @rostok (my answer here), shows the reason to not use the received packets to determine if the host is or not online. On the same subnet, over ipv4, with an offline host, you will get a "unreachable" error, but the packets are received.
For a simple test in ipv4, the linked answer can handle your problem. For a more robust test over ipv4 or ipv6 (that show different behaviour), this could help.
Anyway, the code to get the required data directly from the ping
command,
set "received="
for /f "skip=6 tokens=5 delims==, " %%a in ('ping -n 1 10.1.0.2') do (
if not defined received set "received=%%a"
)
or from the file
set "received="
for /f "usebackq skip=6 tokens=5 delims==, " %%a in ("tmpFile") do (
if not defined received set "received=%%a"
)
Where the skip
clause indicates that the first six lines should be skipped, and the tokens
and delims
select the required element inside the line
Packets: Send = 1, Received = 1,
^ ^^^ ^^ ^^^ ^ Delimiter position
1 2 3 4 5 Token number
But as said, this is not a reliable way to solve the problem