The other answers are great - probably even better than this one, but, as usual, there's another way to do it - this time without needing system utilities or elevated permissions (sudo).
My system runs kubuntu 12.04, so this code will probably work on your system. It should also work on gnome 2.x as well except that the autostart script goes in a different place.
I had a similar issue where I wanted to know when my computer went offline (because my notebook seems to do this occasionally by disabling wifi by itself and I often didn't notice the little red x in the taskbar.)
What I did was to add a small (executable) script to the ~/.kde/Autostart directory which runs my main script every time KDE starts (this takes care of it having a display and keyboard to use):
#!/bin/bash
if [ -x "$HOME/bin/offline_alert" ] ; then
offline_alert &
fi
The main script, offline_alert, tests to see if I'm offline using ping with a few retries to avoid false alarms and then generates a pop-up using yad (same as zenity, only way enhanced!) and plays a sound. In between testing for changes in online status, it sleeps so it doesn't use too many resources.
If you run it manually from the command line, etc., it checks to see if it is already running and gives you the option to end it.
The code that tests for offline is in the "offline" function, so it can easily be modified without affecting the rest of the script.
The images, icons, and sound it uses are hard coded, so you'd have to substitute your own. I found a cool wifi offline icon on the web.
It creates a log file which you may or may not want.
The script is setup to use notifications, but the code is commented out because the notifications went away too quickly and seemed more of a nuisance than a help.
This is just another way to do it and maybe someone will find the code useful.
Joe
/etc/NetworkManager/dispatcher.d/
" You're wrong here stating this. It's more likely that you're making a mistake.