I want my pi to beep when I ping it. I already have a script that makes it beep. How can I run the script when the pi is pinged?
This isn't really a Raspberry Pi issue, however since the Pi runs Linux you can use
tcpdump to filter for all ICMP packets and then use
grep to search for just the requests and then
xargs to run an
echo command to output the
bel character for each ICMP Echo request.
The following command worked for me (I had to configure Putty to not limit the number of alerts in a row):
sudo tcpdump -l -i eth0 icmp 2>&1 | grep --line-buffered request | xargs -n1 echo -ne '\007'
You may need to
sudo apt-get install tcpdump to install
Beware that this command will generate the
bel alert for every ICMP echo request. Other machines on your network can also be sending echo requests to your machine. You may need to filter for the IP address of a specific machine if you only want certain pings to trigger this.
Some notes, the
-l option is needed for
tcpdump to force
tcpdump to not buffer output.
--line-buffered is needed for
grep for the same purpose.