Repository: smicallef/spiderfoot
File: modules/sfp_dnsdb.py (Python)

Code before:
        self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")

        if self.opts["api_key"] == "":
            self.sf.error("You enabled sfp_dnsdb but did not set an API key!", False)
            self.errorState = True
            return None

        if eventData in self.results:
            self.sf.debug(f"Skipping {eventData}, already checked.")
            return None
        self.results[eventData] = True

        responseData = set()
        coHosts = set()

        if eventName == "DOMAIN_NAME":
            rrsetRecords = self.query("rrset", "name", eventData)
            if rrsetRecords is None:
                return None

            for record in rrsetRecords:
                record = record.get("obj")
                if self.checkForStop():
                    return None

                if self.isTooOld(record.get("time_last")):
                    continue

                if record.get("rrtype") not in (
                    "A",
                    "AAAA",
                    "MX",
                    "NS",
                    "TXT",
                    "CNAME",
                ):
                    continue

                self.emit("RAW_RIR_DATA", str(record), event)
                for data in record.get("rdata"):
                    data = data.rstrip(".")
                    if data in responseData:
                        continue
                    responseData.add(data)

                    if record.get("rrtype") == "A":
                        if not self.sf.validIP(data):
                            self.sf.debug(f"Skipping invalid IP address {data}")
                            continue

                        if self.opts["verify"] and not self.sf.validateIP(

Review comment (suggestion):
Any chance `.get()` returns `None` here? Might make sense to make this `.get("time_last", 0)` instead.

Code after:
        if self.errorState:
            return None

        self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")

        if self.opts["api_key"] == "":
            self.sf.error("You enabled sfp_dnsdb but did not set an API key!", False)
            self.errorState = True
            return None

        if eventData in self.results:
            self.sf.debug(f"Skipping {eventData}, already checked.")
            return None
        self.results[eventData] = True

        responseData = set()
        coHosts = set()

        if eventName == "DOMAIN_NAME":
            rrsetRecords = self.query("rrset", "name", eventData)
            if rrsetRecords is None:
                return None

            self.emit("RAW_RIR_DATA", str(rrsetRecords), event)

            for record in rrsetRecords:
                record = record.get("obj")
                if self.checkForStop():
                    return None

                if self.isTooOld(record.get("time_last", 0)):
                    continue

                if record.get("rrtype") not in (
                    "A",
                    "AAAA",
                    "MX",
                    "NS",
                    "TXT",
                    "CNAME",
                ):
                    continue

                for data in record.get("rdata"):
                    data = data.rstrip(".")
                    if data in responseData:
                        continue
                    responseData.add(data)

                    if record.get("rrtype") == "A":
                        if not self.sf.validIP(data):