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?

1 Answer 1


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 tcpdump.

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.

  • I am not clear how this runs a script. When you say "bel character" are you talking about a system beep that might come out or the hdmi or something? Because I am just using a piezo buzzer that it attached to a gpio pin. The command I tried was sudo tcpdump -l -i eth0 icmp 2>&1 | grep --line-buffered request | sudo bash beep.sh but that just beeps once then exits. Jun 9, 2022 at 16:59
  • The command you listed should beep once for each ping. I thought that was what you wanted. If not, please update your question with more details. Jun 9, 2022 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.