A bit more involved than David S' version, since it queries the control port for an appropriate SOCKS listener. This makes it easier to use.