Bash script to toggle wifi in lion

Assuming your hardware is somewhat similar to mine:

networksetup -setairportpower en1 on
networksetup -setairportpower en1 off

You can run networksetup -listallhardwareports to find the device (en1) of your Wi-Fi in case it's different.

To toggle put something like the following lines into a script or shell function:

[[ "$(networksetup -getairportpower en1)" == *On ]] && v=off || v=on
networksetup -setairportpower en1 $v

#!/bin/bash

device=$(networksetup -listallhardwareports |
grep -E '(Wi-Fi|AirPort)' -A 1 | grep -o en.)
[[ "$(networksetup -getairportpower $device)" == *On ]] && v=off || v=on
networksetup -setairportpower $device $v

The port name is Wi-Fi on 10.7 and AirPort on 10.6. The device name can be at least en0, en1, or en2 depending on your setup.