How to get only the reply line of a ping test on Windows

后端 未结 7 1408
你的背包
你的背包 2021-02-04 12:01

Usually, when pinging a server IP address we have this in return:

Pinging  with 32 bytes of data:
Reply from  : bytes=32 time=151 TTL         


        
7条回答
  •  自闭症患者
    2021-02-04 12:16

    It's pretty simple from within batch, but from command line... ugly is major understatement:

    (for /f "skip=1 delims=" %F in ('ping -n 1 localhost') do @if not defined _A @echo %F&set _A=0) &set "_A="
    

    But it does the trick, prints second line (whatever it will happen to contain) and skips the rest. You may change line it prints changing skip=.

    If you have powershell available, you could simply do: (yes I know it's not how pinging is supposed to be done in PS): powershell "ping -n 1 localhost | select -index 2". You may need to play with index, as on my (XP) laptop ping inserts addtional CR in each line, which has an effect of double - spacing output from PS.

提交回复
热议问题