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 ]] &amp;&amp; v=off || v=on
networksetup -setairportpower en1 $v