Tuesday, March 31, 2009

Detecting My Wifi Network

OpenBSDOn my laptop, I generally don't have /etc/hostname.* files. Since I don't know where I'm going to be, I don't know which interface I'm going to be using. So, I'll manually run `sudo dhclient em0` or `sudo ifconfig ral0 nwid foo && sudo dhclient ral0`. But, I'm often using my home wireless network.

So, I added a little bit of magic to my /etc/rc.local:

## wifi
if [ "$1" = "" -o "$1" = "wifi" ]; then
ifconfig ral0 up

## Reset ral0
ifconfig ral0 -bssid -chan media autoselect nwid "" -nwkey -wpa -wpapsk

## If at home or at Dad's
if [ `ifconfig ral0 scan | grep -c "00:0f:66:18:62:e0"` -gt 0 ]; then
/sbin/ifconfig ral0 nwid MySsid wpa wpapsk `/sbin/wpa-psk MySsid MyKey` > /dev/null 2>&1
/sbin/dhclient ral0 > /dev/null 2>&1
echo -n ' wifi'
ifconfig ral0 down