Factor out common port-finding code

Fixes bug where we would infinite-loop trying to find an HTTP server
port when all ports were unavailable (e.g. range [80,80] and no root
permission)

Also fixes bug where SSH port forwarding would try ports up to but not
including HostPortMax.

Also add clarification in error messages for which port range to expand