Active connection check in firewall scripts

Jan 30, '02 11:27:15PM

Contributed by: Anonymous

Many folks out there have been using ipfw with their OS X machines. Unfortunately, many scripts out there in tutorials will hang if your machine is not connected/dialed into a network.

I've found this issue can be easily solved by adding the following lines at the top of your firewall script (right after the top #! line):

if ! ifconfig -a | grep "status:" | awk '{ print $6 }' | grep "^active" > /dev/null
then
echo "exiting early"
exit
fi
This will run ifconfig and check for active interfaces. Note that all interfaces seem to be up in OS X, whether they are actually connected to a network or not. If it doesn't find any, it will abort the script, thus not hanging forever.

I use my script additions with a script I modified from here.

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020130232715106