Audible Ping

By: on August 12, 2005

Does your internet go away occasionally? Do you have a computer hooked up to a moderately loud stereo system? Want to know as soon as the link comes back? Here’s a script (put it in a file, e.g. ~/bin/audible-ping) that pings some outside host, playing a short .wav file when ping finally starts to get some responses:

    #!/bin/sh
   ping "$@" |
    grep --line-buffered 'bytes from' 2>&1 |
   perl -e 'while (<>) { `play /path/to/the/ping/sound.wav`; }'

It will play the .wav file once per successful ping packet reply. (Obviously you’ll need to come up with your own short beep-like sound file, and replace the path given above appropriately; use play‘s --volume=n parameter to adjust the volume to taste.)

We use it here when our DSL connection goes away, running

$ audible-ping 123.123.123.123

on our jukebox computer. (IP address changed to protect the innocent.) We use a literal IP address rather than a DNS name because if your ‘net is AWOL, the DNS query will time out and ping will exit rather than continuing to retry. The script lets us know the very moment our DSL connection comes back.

FacebookTwitterGoogle+

3 Comments

  1. Ian Morrison says:

    Under FreeBSD very similar functionality is built into the standard ping program. From the ping(8) manpage:

    -A Audible. Output a bell (ASCII 0x07) character when no packet is received before the next packet is transmitted. To cater for round-trip times that are longer than the interval between transmissions, further missing packets cause a bell only if the maximum number of unreceived packets has increased.

    -a Audible. Include a bell (ASCII 0x07) character in the output when any packet is received. This option is ignored if other format options are present.

    so if you ran ping -A 123.123.123.123, your jukebox would start beeping as soon as the dsl connection went down.

    ian

  2. Adam Spiers says:

    Seven years later, here’s a slightly more sophisticated audible ping tool which I just wrote :) Pitch represents latency, so you can “hear” the quality of the connection:

    http://blog.adamspiers.org/2012/02/11/tool-building-hacks-1-audible-pings/

Post a comment

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>