Collect all the Sonar Reverse DNS records for the provided zone and add them to NetworkX graph
(graph, zone, groups, mongo_connector, ip_manager)
| 169 | |
| 170 | |
| 171 | def find_srdns_by_zone(graph, zone, groups, mongo_connector, ip_manager): |
| 172 | """ |
| 173 | Collect all the Sonar Reverse DNS records for the provided zone and add them to NetworkX graph |
| 174 | """ |
| 175 | srdns_collection = mongo_connector.get_sonar_reverse_dns_connection() |
| 176 | rdns_results = srdns_collection.find({"zone": zone}) |
| 177 | |
| 178 | for result in rdns_results: |
| 179 | zone_g_index = add_to_list(zone, groups) |
| 180 | if result["fqdn"] != zone: |
| 181 | graph.add_node( |
| 182 | result["fqdn"].replace("." + zone, ""), |
| 183 | data_type="domain", |
| 184 | type=zone_g_index, |
| 185 | depends=[zone], |
| 186 | dependedOnBy=[result["ip"]], |
| 187 | docs="", |
| 188 | ) |
| 189 | else: |
| 190 | graph.add_node( |
| 191 | result["fqdn"], |
| 192 | data_type="tld", |
| 193 | type=zone_g_index, |
| 194 | depends=[], |
| 195 | dependedOnBy=[result["ip"]], |
| 196 | docs="", |
| 197 | ) |
| 198 | temp = result["ip"].split(".") |
| 199 | |
| 200 | ip_group = ".".join(temp[:-1]) |
| 201 | if ip_manager.is_aws_ip(result["ip"]): |
| 202 | ip_group = "aws" |
| 203 | elif ip_manager.is_akamai_ip(result["ip"]): |
| 204 | ip_group = "akamai" |
| 205 | elif ip_manager.is_azure_ip(result["ip"]): |
| 206 | ip_group = "azure" |
| 207 | elif ip_manager.is_gcp_ip(result["ip"]): |
| 208 | ip_group = "gcp" |
| 209 | |
| 210 | ip_g_index = add_to_list(ip_group, groups) |
| 211 | graph.add_node( |
| 212 | result["ip"], |
| 213 | data_type="ip", |
| 214 | type=ip_g_index, |
| 215 | depends=[result["fqdn"].replace("." + zone, "")], |
| 216 | dependedOnBy=[], |
| 217 | docs="", |
| 218 | ) |
| 219 | graph.add_edge(zone, result["fqdn"].replace("." + zone, ""), value=2) |
| 220 | graph.add_edge(result["fqdn"].replace("." + zone, ""), result["ip"], value=1) |
| 221 | |
| 222 | |
| 223 | def build_docs(node, zone, groups): |
no test coverage detected