On Wed, 2005-12-28 at 15:26:56 -0500, Roy Morris proclaimed...

> What's the best way to switch between say three static ip locations
> and one dhcp? I could write a quick script that changes them unless
> I am missing something obvious? If a script is the answer then when
> is the best time to run it?

Something like this:

#!/bin/sh
#; Connect to whatever wlan we're near
#; $Id: etc_rc.wlan,v 1.1 2004/11/03 03:27:57 eric Exp $

PATH="/usr/sbin:/sbin:/usr/bin:/bin"
DATE="`date`"
PFRULES="/etc/pf.conf.wlan"

if [ -z "$1" ]; then
 echo ""
 echo "rc.wlan: need argument"
 echo "usage: rc.wlan <wlan id>"
 echo ""
 exit 2
fi

if [ ! -f "$PFRULES" ]; then
 echo " ! $PFRULES not found, exiting."
 echo "done."
 echo ""
fi


echo ""
echo "$DATE: $0" 
echo "* Connecting to $1..."
case $1 in 
 home | washington )
  wicontrol -p 1 -e 1 -T 1 -f 8 -n washington )
        -k 0xf00f00f00f00f00f00f00f00f0
 ;;

 # hilton, castle hill, budapest, 2004
 hilton )
  wicontrol -e 0 -p 1 -n WIERA
 ;;

 # hotel dubrovnik, zagreb, croatia, 2004
 zagreb )
  wicontrol -e 0 -p 1 -n ZNET-Papirus
 ;;

 # more can be added as needed....

 kill | stop | down )
  ifconfig wi0 down
  route delete default
  ifconfig wi0 delete
  echo "Safe to pop out network card now."
  exit 0
 ;;

 * )
   echo "! Unrecognized network name, exiting."
   echo "done."
   echo ""
   exit 2
 ;;
esac

echo "* Getting an IP address with dhclient..."
dhclient wi0

echo "* Adding security filters..."
pfctl -d -F all ;
pfctl -f $PFRULES -e

echo "done."
echo ""

exit 0

Reply via email to