def valid_port(ctx, param, value):
    """
    This function tries to cast the port to integer. If it's not possible, the
    initial string value is returned.

    :param ctx: the click context
    :param param: the click param
    :param value: the port name or number
    :return: the port as a string or integer
    """
    try:
        value = int(value)
    except ValueError:
        pass

    return value