Skip to content

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

Removed sfp_freegeoip.py and introduced sfp_ipstack to use IPStack.com

Steve Micallefb4c12576b153
diff --git a/modules/sfp_freegeoip.py b/modules/sfp_ipstack.py
similarity index 60%
rename from modules/sfp_freegeoip.py
rename to modules/sfp_ipstack.py
index a697935b..44c3a337 100644
--- a/modules/sfp_freegeoip.py
+++ b/modules/sfp_ipstack.py
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
# -------------------------------------------------------------------------------
-# Name: sfp_freegeoip
+# Name: sfp_ipstack
# Purpose: SpiderFoot plug-in to identify the Geo-location of IP addresses
-# identified by other modules using freegeoip.net.
+# identified by other modules using ipstack.com.
#
# Author: Steve Micallef <[email protected]>
#
-# Created: 18/02/2013
-# Copyright: (c) Steve Micallef 2013
+# Created: 20/08/2018
+# Copyright: (c) Steve Micallef 2018
# Licence: GPL
# -------------------------------------------------------------------------------
@@ -15,13 +15,18 @@ import json
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
-class sfp_freegeoip(SpiderFootPlugin):
- """FreeGeoIP:Footprint,Investigate,Passive:Real World::Identifies the physical location of IP addresses identified using freegeoip.net."""
-
+class sfp_ipstack(SpiderFootPlugin):
+ """ipstack:Footprint,Investigate,Passive:Real World:apikey:Identifies the physical location of IP addresses identified using ipstack.com."""
# Default options
- opts = {}
- results = dict()
+ opts = {
+ "api_key": ""
+ }
+ optdescs = {
+ "api_key": "Your ipstack.com API key."
+ }
+ results = None
+ errorState = False
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
@@ -48,6 +53,9 @@ class sfp_freegeoip(SpiderFootPlugin):
self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
+ if self.errorState:
+ return None
+
# Don't look up stuff twice
if eventData in self.results:
self.sf.debug("Skipping " + eventData + " as already mapped.")
@@ -55,22 +63,28 @@ class sfp_freegeoip(SpiderFootPlugin):
else:
self.results[eventData] = True
- res = self.sf.fetchUrl("https://freegeoip.net/json/" + eventData,
+ res = self.sf.fetchUrl("http://api.ipstack.com/" + eventData + "?access_key=" + self.opts['api_key'],
timeout=self.opts['_fetchtimeout'], useragent=self.opts['_useragent'])
if res['content'] is None:
self.sf.info("No GeoIP info found for " + eventData)
+
try:
hostip = json.loads(res['content'])
+ if 'success' in hostip and hostip['success'] == False:
+ self.sf.error("Invalid ipstack.com API key or usage limits exceeded.", False)
+ self.errorState = True
+ return None
except Exception as e:
self.sf.debug("Error processing JSON response.")
return None
- self.sf.info("Found GeoIP for " + eventData + ": " + hostip['country_name'])
- countrycity = hostip['country_name']
+ if 'country_name' in hostip:
+ self.sf.info("Found GeoIP for " + eventData + ": " + hostip['country_name'])
+ countrycity = hostip['country_name']
- evt = SpiderFootEvent("GEOINFO", countrycity, self.__name__, event)
- self.notifyListeners(evt)
+ evt = SpiderFootEvent("GEOINFO", countrycity, self.__name__, event)
+ self.notifyListeners(evt)
return None
-# End of sfp_freegeoip class
+# End of sfp_ipstack class