Add portal_hostname_from_client_ip function

- Reduce code duplication by using a new portal_hostname_from_client_ip function.
- Suppress CaptivePortal ports in URL if they are 80 or 443