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'
  else
    ifconfig ral0 down
  fi
fi

2 Responses to “Detecting My Wifi Network”


  1. Nice and simple. I immediately remembered a related undeadly article:
    http://undeadly.org/cgi?action=article&sid=20071224164233
    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).

Leave a Reply