All of this from the command line, of course!
There are a couple of commands to do this, well hidden in Mac OS X:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I \ | awk '/ SSID/ {print substr($0, index($0, $2))}'
And also:
networksetup -getairportnetwork en1 | cut -c 25- networksetup -getairportnetwork en1 | cut -c 24-
These are not mine, they come from the following sites. Hope this helps!