Extrct IP from ping

Hi guys,
I'm looking for a script to extract the IP address reported by the command:

$> ping -c 1 192.168.1.254
PING 192.168.192.254 (192.168.192.254) 56(84) bytes of data.
64 bytes from 192.168.192.254: icmp_seq=1 ttl=64 time=139 ms

--- 192.168.192.254 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 139.136/139.136/139.136/0.000 ms

What I have to get is the value after the "64 bytes from" and only the reported IP not the data after the ":".

In my real case the ping will be executed on broadcast address as 192.168.192.255.

I'm using a BASH script.
Thanks in advance

play around with grep/awk and you'll have a solution
$ > ping -c 1 192.168.1.254 | grep "64 bytes from"|awk '{print $4}'

You can also check with nmap whole network

nmap -sP 192.168.1.1-254 | grep Host | awk '{print $2}'

Regards,
Bash

For single query of ping

ping -c 1 192.168.1.156 | grep "64 bytes from " | awk '{print $4}' | cut -d":" -f1

192.168.1.156

Regards,
Bash

Your example show the Useless Use of grep and cut when awk can do all.

ping -c 1 192.168.1.156 | awk -F" |:" '/from/{print $4}'

Regards,
Dan

With awk only:

ping -c 1 192.168.1.254 | awk -F'[ :]' 'NR==2 { print $4 }'

Hi Dan,

I just gave the alternate method, as you see that was my second reply, but any way thanks for your comments.

Regards,
Bash

No problem, we just try to find the best/fast solution.

Regards,
Dan

Many thanks to everyone for suggestions