I needed a way to run a Unix script any time my IP address changed, either when moving from one network to another, or when my DHCP-assigned IP refreshed. After doing a bit of hunting around, I discovered that the /System -> Library -> SystemConfiguration -> Kicker.bundle -> Contents -> Resources -> set-hostname script was run during all of these events. It is also run by just unplugging and replugging the Ethernet cable. I modified the script to call another script that I keep in /usr/local/bin called networkchanged. I added this code to the end of set-hostname:
if [ -x /usr/local/bin/networkchange ] ; then
/usr/local/bin/networkchange
fi
The only command that follows this addition is the exit 0 from the original script. You could put all your new commands into the original set-hostname, but it is easier for me to remember the script is in /usr/local/bin with all my other custom scripts. Don't forget to create a backup of the original script in case you need it later.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20040923133938271