Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

windows

cmd

ping

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

Pinging <IP address> with 32 bytes of data:
Reply from <ip> : bytes=32 time=151 TTL=121
Reply from <ip> : bytes=32 time=151 TTL=121
Reply from <ip> : bytes=32 time=151 TTL=121
Reply from <ip> : bytes=32 time=151 TTL=121

Ping statistics for <IP address>:
packets: sent = 4, Received = 4, lost = 0 (0% loss),
Approximate round trip times in milli-secounds:
Minimum = 151ms, Maximum = 151 ms, Average = 151 ms

How do I get only the following line (only the reply line of one ping test) in return by a simple command in cmd.exe on Windows (whatever Windows language used)?

Reply from <IP address> : bytes=32 time=151 TTL=121

Maybe the simplest way is to display only the second line? How should this be done? Because I don't know how to do it on Windows.

like image 764
mastermind Avatar asked Sep 07 '12 14:09

mastermind


People also ask

What is the ping response?

Ping works by sending an Internet Control Message Protocol (ICMP) Echo Request to a specified interface on the network and waiting for a reply. When a ping command is issued, a ping signal is sent to a specified address. When the target host receives the echo request, it responds by sending an echo reply packet.

How do I ping 1000 packets in cmd?

Type ping -f -l 1000 <default gateway address> and press Enter. Note the addition of the -f option to prevent fragmentation of the packet. Observe the results.


1 Answers

For some reason, I couldn't get the FIND pipe to work in a powershell 5.1 shell. Feeling like this was all overly complicated, I thought if only I could grep the Reply line? I then found the powershell equivalent! I just used select-string on the first line matching 'Reply' which gave me the one line output I was looking for. So this worked very simply and easy for me.

ping -n 1 <hostname/IP> | select-string -pattern 'Reply'
like image 54
G_Style Avatar answered Oct 23 '22 21:10

G_Style