import ipaddress


def compare_addresses(allowed_networks, test_addresses):
    """Compare addresses from A records to allowed networks, return list of bad addresses."""
    bad_addresses = []
    # Compare addresses to allowed networks.
    for address in test_addresses:
        ok_address = False
        for network in allowed_networks:
        #    print(" %s" % network)
            if ipaddress.IPv4Address(address) in network:
                ok_address = True
        if not ok_address:
            bad_addresses.append(address)
    return bad_addresses