Get the list of all IPs that are being tracked by Marinus.
(ip_manager, all_dns_collection)
| 163 | |
| 164 | |
| 165 | def get_ips(ip_manager, all_dns_collection): |
| 166 | """ |
| 167 | Get the list of all IPs that are being tracked by Marinus. |
| 168 | """ |
| 169 | ips = set([]) |
| 170 | ip_context = [] |
| 171 | |
| 172 | domain_results = all_dns_collection.find({"type": "a", "zone": {"$ne": ""}}) |
| 173 | for result in domain_results: |
| 174 | if not ip_manager.is_local_ip(result["value"]): |
| 175 | ips.add(result["value"]) |
| 176 | ip_context.append( |
| 177 | { |
| 178 | "ip": result["value"], |
| 179 | "domain": result["fqdn"], |
| 180 | "source": "all_dns", |
| 181 | "zone": result["zone"], |
| 182 | } |
| 183 | ) |
| 184 | |
| 185 | for ipz in ip_manager.Tracked_CIDRs: |
| 186 | if ipz.version == 4: |
| 187 | for ip in ipz: |
| 188 | if ip != ipz.network and ip != ipz.broadcast: |
| 189 | ips.add(str(ip)) |
| 190 | |
| 191 | # Don't want to look like a network scan |
| 192 | # Set doesn't support random.shuffle |
| 193 | ips_list = list(ips) |
| 194 | random.shuffle(ips_list) |
| 195 | |
| 196 | return (ips_list, ip_context) |
| 197 | |
| 198 | |
| 199 | def check_ip_context(ip, ip_context): |