I am not familiar with the commands but I think the script structure should look like:
#Get IP Address
ifconfig -a | grep 192.169
if [ $? -eq 0 ]
then
#disable firewall
if [`defaults read "/Library/Preferences/com.apple.sharing.firewall" state` -eg 1]
then
defaults write /Library/Preferences/com.apple.alf globalstate -int 0
killall -HUP socketfilterfw
echo "Firewall Off"
#Enable firewall to Set access for specific services and applications
elif [`defaults read "/Library/Preferences/com.apple.sharing.firewall" state` -eg 0]
then
defaults write /Library/Preferences/com.apple.alf globalstate -int 1
killall -HUP socketfilterfw
echo "Firewall On"
fi
fi