def getPortFromUrl(url):
    """ Get Port number for given url """
    if not url:
        raise ValueError("url undefined")
    if url.startswith("http://"):
        default_port = 80
    elif url.startswith("https://"):
        default_port = 443
    elif url.startswith("http+unix://"):
        # unix domain socket
        return None
    else:
        raise ValueError(f"Invalid Url: {url}")

    start = url.find('//')
    port = None
    dns = url[start:]
    index = dns.find(':')
    port_str = ""
    if index > 0:
        for i in range(index+1, len(dns)):
            ch = dns[i]
            if ch.isdigit():
                port_str += ch
            else:
                break
    if port_str:
        port = int(port_str)
    else:
        port = default_port

    return port