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


  1. Nice and simple. I immediately remembered a related undeadly article:
    Now that I'm looking at it -- it was you who posted it there ;-)

  2. Darn. When I wrote that (in my rc.local and on my website), I forgot about that Undeadly article. D. Adam Karim clearly deserves credit here for the work I posted. Thank you, Adam (and Aaron for reminding me).