0

As know the result of ping any IP is consists of two part.The fist one is reply from .... and It is just one line and the second part which is multiple lines belongs to statistics.I want two remove second part. I just need the first line to output not statistics . Is there any command to do that?

3 Answers3

0
set "line="
for /f "delims=" %%a in ('ping 127.0.0.1 -n 1') do if not defined line set "line=%%~a"
echo %line%
Endoro
  • 37,015
  • 8
  • 50
  • 63
0

Here's an alternative.

ping www.google.com -n 1 |find /i "reply from" >> file.log

you may just want the info that this provides:

ping www.google.com -n 1 |find /i "TTL" >> file.log
foxidrive
  • 40,353
  • 10
  • 53
  • 68
0

This is an old thread but Google brought me here, so if it does for anyone else this may be helpful:

Here's one that gives a one line reply whether the ping responds or fails:

ping -n 1 127.0.0.1 | find "y "

You'll get either:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

--or--

Ping request could not find host 127.0.0.1. Please check the name and try again.

The "-n 1" limits the ping process to just 1 ping and the find "y " is used since the letter "y" and a space is common to both responses - in the words "Reply " and "try ".

Stephan
  • 53,940
  • 10
  • 58
  • 91
Techie
  • 1