def _get_ip_filter(external):
    """
    Get the right peace of sql query to filter ip addresses for external and 
    internal machines
    """
    
    if external:
        return """(mc.ip_address not like '{{ ip_pattern1 }}'
                      and mc.ip_address not like '{{ ip_pattern2 }}')""" 
    
    return """(mc.ip_address like '{{ ip_pattern1 }}'
              or mc.ip_address like '{{ ip_pattern2 }}')"""