Begin Main...
(logger=None)
| 86 | |
| 87 | |
| 88 | def main(logger=None): |
| 89 | """ |
| 90 | Begin Main... |
| 91 | """ |
| 92 | if logger is None: |
| 93 | logger = LoggingUtil.create_log(__name__) |
| 94 | |
| 95 | now = datetime.now() |
| 96 | print("Starting: " + str(now)) |
| 97 | logger.info("Starting...") |
| 98 | |
| 99 | mongo_connector = MongoConnector.MongoConnector() |
| 100 | dns_manager = DNSManager.DNSManager(mongo_connector) |
| 101 | jobs_manager = JobsManager.JobsManager(mongo_connector, "extract_mx_domains") |
| 102 | google_dns = GoogleDNS.GoogleDNS() |
| 103 | |
| 104 | jobs_manager.record_job_start() |
| 105 | |
| 106 | dns_names = [] |
| 107 | round_two = [] |
| 108 | |
| 109 | zones = ZoneManager.get_distinct_zones(mongo_connector) |
| 110 | |
| 111 | # Collect the list of domains from the MX Records |
| 112 | extract_mx_names(dns_names, dns_manager) |
| 113 | |
| 114 | input_list = [] |
| 115 | |
| 116 | # Some MX records point to the third-party domains. |
| 117 | # Therefore, we filter to only the root domains that belong to the tracked company. |
| 118 | logger.info("Pre-filter list: " + str(len(dns_names))) |
| 119 | for hostname in dns_names: |
| 120 | zone = get_tracked_zone(hostname, zones) |
| 121 | if zone != None: |
| 122 | ips = google_dns.fetch_DNS_records(hostname) |
| 123 | |
| 124 | # Pause to prevent DoS-ing of Google's HTTPS DNS Service |
| 125 | time.sleep(1) |
| 126 | |
| 127 | if ips is not None and ips != []: |
| 128 | for ip_addr in ips: |
| 129 | temp_zone = get_tracked_zone(ip_addr["fqdn"], zones) |
| 130 | if temp_zone is not None: |
| 131 | record = {"fqdn": ip_addr["fqdn"]} |
| 132 | record["zone"] = temp_zone |
| 133 | record["created"] = datetime.now() |
| 134 | record["type"] = ip_addr["type"] |
| 135 | record["value"] = ip_addr["value"] |
| 136 | record["status"] = "unknown" |
| 137 | input_list.append(record) |
| 138 | |
| 139 | if ip_addr["type"] == "cname" and is_tracked_zone( |
| 140 | ip_addr["value"], zones |
| 141 | ): |
| 142 | add_to_round_two(ip_addr["value"], round_two) |
| 143 | else: |
| 144 | logger.warning("Failed IP Lookup for: " + hostname) |
| 145 | else: |
no test coverage detected