def _select_control_ip(ip_addresses, control_from_inside):
    """
    Selects either an internal or external IP address (the first one), depending
    on the value of the parameter `control_from_inside`. We need an IPv4 address to connect to,
    since is the safest way to ensure routability.
    """
    for ip_address in ip_addresses:
        if control_from_inside and ip_address.access == 'private' and ip_address.family == "IPv4" :
            # Good enough
            return ip_address
        if not control_from_inside and ip_address.access == 'public' and ip_address.family == "IPv4" :
            # Good enough gain
            return ip_address

    # Got here, not a good thing
    return None