Get the list of IPs
(ip_manager, all_dns_collection)
| 66 | |
| 67 | |
| 68 | def get_ips(ip_manager, all_dns_collection): |
| 69 | """ |
| 70 | Get the list of IPs |
| 71 | """ |
| 72 | ips = set([]) |
| 73 | ip_context = [] |
| 74 | |
| 75 | domain_results = all_dns_collection.find({"type": "a", "zone": {"$ne": ""}}) |
| 76 | for result in domain_results: |
| 77 | if not ip_manager.is_local_ip(result["value"]): |
| 78 | ips.add(result["value"]) |
| 79 | ip_context.append( |
| 80 | { |
| 81 | "ip": result["value"], |
| 82 | "domain": result["fqdn"], |
| 83 | "source": "all_dns", |
| 84 | "zone": result["zone"], |
| 85 | } |
| 86 | ) |
| 87 | |
| 88 | for ipz in ip_manager.Tracked_CIDRs: |
| 89 | if ipz.version == 4: |
| 90 | for ip in ipz: |
| 91 | if ip != ipz.network and ip != ipz.broadcast: |
| 92 | ips.add(str(ip)) |
| 93 | # ip_context.append({'ip': str(ip), 'source': 'ip_zone'}) |
| 94 | |
| 95 | # Don't want to look like a network scan |
| 96 | # Set doesn't support random.shuffle |
| 97 | ips_list = list(ips) |
| 98 | random.shuffle(ips_list) |
| 99 | |
| 100 | return (ips_list, ip_context) |
| 101 | |
| 102 | |
| 103 | def check_ip_context(ip, ip_context): |