Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

sfp_whois: Update module code style (#1249)

bcolesd35203761308
diff --git a/modules/sfp_whois.py b/modules/sfp_whois.py
index d85cd647..68b05db5 100644
--- a/modules/sfp_whois.py
+++ b/modules/sfp_whois.py
@@ -71,50 +71,55 @@ class sfp_whois(SpiderFootPlugin):
self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")
- try:
- data = None
- if eventName != "NETBLOCK_OWNER":
- whoisdata = whois.whois(eventData)
- if whoisdata:
- data = whoisdata.text
- else:
- qry = eventData.split("/")[0]
- ip = IPAddress(qry) + 1
- self.sf.debug("Querying for IP ownership of " + str(ip))
- r = ipwhois.IPWhois(ip)
- whoisdata = r.lookup_rdap(depth=1)
- if whoisdata:
- data = str(whoisdata)
- if not data:
- self.sf.error("Unable to perform WHOIS on " + eventData)
- return
- except Exception as e:
- self.sf.error("Unable to perform WHOIS on " + eventData + ": " + str(e))
- return
-
- # This is likely to be an error about being throttled rather than real data
- if len(data) < 250:
- self.sf.error("Throttling from Whois is probably happening.")
- return
-
if eventName.startswith("DOMAIN_NAME"):
typ = "DOMAIN_WHOIS"
- if eventName.startswith("NETBLOCK"):
+ elif eventName.startswith("NETBLOCK"):
typ = "NETBLOCK_WHOIS"
- if eventName.startswith("AFFILIATE_DOMAIN_NAME"):
+ elif eventName.startswith("AFFILIATE_DOMAIN_NAME"):
typ = "AFFILIATE_DOMAIN_WHOIS"
- if eventName.startswith("CO_HOSTED_SITE_DOMAIN"):
+ elif eventName.startswith("CO_HOSTED_SITE_DOMAIN"):
typ = "CO_HOSTED_SITE_DOMAIN_WHOIS"
- if eventName == "SIMILARDOMAIN":
+ elif eventName == "SIMILARDOMAIN":
typ = "SIMILARDOMAIN_WHOIS"
+ else:
+ self.sf.error(f"Invalid event type: {eventName}")
+ return
+
+ if eventName == "NETBLOCK_OWNER":
+ qry = eventData.split("/")[0]
+ ip = IPAddress(qry) + 1
+ self.sf.debug(f"Sending RDAP query for IP address: {ip}")
+ try:
+ # TODO: this should use the configured proxy
+ r = ipwhois.IPWhois(qry)
+ data = r.lookup_rdap(depth=1)
+ except Exception as e:
+ self.sf.error(f"Unable to perform WHOIS query on {qry}: {e}")
+ else:
+ self.sf.debug("Sending WHOIS query for domain: {eventData}")
+ try:
+ whoisdata = whois.whois(eventData)
+ data = str(whoisdata.text)
+ except Exception as e:
+ self.sf.error(f"Unable to perform WHOIS query on {qry}: {e}")
+
+ if not data:
+ self.sf.error(f"No WHOIS record for {eventData}")
+ return
+
+ # This is likely to be an error about being throttled rather than real data
+ if len(data) < 250:
+ self.sf.error(f"WHOIS data ({len(data)} bytes) is smaller than 250 bytes. Throttling from WHOIS server is probably happening. Ignoring response.")
+ return
rawevt = SpiderFootEvent(typ, data, self.__name__, event)
self.notifyListeners(rawevt)
- if 'registrar' in whoisdata:
- if eventName.startswith("DOMAIN_NAME") and whoisdata['registrar'] is not None:
- evt = SpiderFootEvent("DOMAIN_REGISTRAR", whoisdata['registrar'],
- self.__name__, event)
- self.notifyListeners(evt)
+ if eventName.startswith("DOMAIN_NAME"):
+ if whoisdata:
+ registrar = whoisdata.get('registrar')
+ if registrar:
+ evt = SpiderFootEvent("DOMAIN_REGISTRAR", registrar, self.__name__, event)
+ self.notifyListeners(evt)
# End of sfp_whois class