It took a few syntax changes to port it to OS X (view source), but it works exactly as it did in FreeBSD. sockstat is a Perl script which will present a list of programs to which are connected to or from you, and displays them in Terminal. This is useful because, at any given time, you can peek in to see if sshd, Apple Remote Desktop, or even Safari, etc., are connected.
Next time you start a service on your Mac with OS X, and you're not sure what port it happens to run on, try sockstat. Enjoy!
[robg adds: To use this script, first copy the text from the view source link, and then switch to Terminal. Open a new file for editing somewhere on your command path (/usr/local/bin, your user's ~/bin, etc.). Use vi or pico or whatever you're comfortable with (you could even paste it into TextEdit or antoher GUI editor). Once pasted, save the file as sockstat, make it executable with chmod +x sockstat, and then type hash to tell the bash shell to find new programs. I tested it, and it works as described -- use the linked man page above for instructions, as the help is not included with this source.]

