Note: if you need a simple connection icon, check out BitBar and its internet checker plugin.
This program notifies you when Internet goes down and when it comes back up.
It pings Google's DNS every 4 seconds; when a ping fails it quickly tries a few more times and switches to downtime mode. When Internet is available again, the cycle restarts.
bash
ping
osascript
(AppleScript, for the OSX notifications)
Remove lines with osascript
to make it compatible outside OS X