def _fetch_geo(self, geoitem): """ fetch geoip addresses, if not downloaded or outdated force an update :return: iterator """ do_update = True if os.path.isfile('/usr/local/share/GeoIP/alias/NL-IPv4'): fstat = os.stat('/usr/local/share/GeoIP/alias/NL-IPv4') if (time.time() - fstat.st_mtime) < (86400 - 90): do_update = False if do_update: syslog.syslog(syslog.LOG_ERR, 'geoip updated (files: %s lines: %s)' % geoip.download_geolite()) for proto in self._proto.split(','): geoip_filename = "/usr/local/share/GeoIP/alias/%s-%s" % (geoitem, proto) if os.path.isfile(geoip_filename): with open(geoip_filename) as f_in: for line in f_in: for address in self._parse_address(line): yield address