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.
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.
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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With