from collections import defaultdict from utils import prettyprint import ipaddress new_ips_data = defaultdict(list) cloud_ranges_file = open("google_ranges.txt", "r") cloud_ranges = [x.strip() for x in cloud_ranges_file.readlines()] def process_list(item: str): l = item.strip() if l.startswith('#') or l == '': return True [range, comment] = [x.strip() for x in l.split('#')] for cloud_range in cloud_ranges: if ipaddress.ip_network(range).subnet_of(ipaddress.ip_network(cloud_range)): new_ips_data[cloud_range].append(f'{comment} ({range})') return False return True def main(file_data: list[str]): file_data = list(filter(process_list, file_data)) ips = list(new_ips_data.keys()) for ip in ips: file_data.append(prettyprint(ip, 'google_range :: ' + ', '.join(new_ips_data[ip])) + '\n') return file_data