def main(): """ Execute the daemon. """ if len(sys.argv) != 2: print >> sys.stderr, USAGE % os.path.basename(sys.argv[0]) return 1 logging.config.fileConfig(sys.argv[1]) try: logger.info("Reading config file at '%s'", sys.argv[1]) parser = utils.make_config_parser(sys.argv[1]) iface = parser.get('uwhoisd', 'iface') port = parser.getint('uwhoisd', 'port') logger.info("Listen on %s:%d", iface, port) uwhois = UWhois() uwhois.read_config(parser) cache = caching.get_cache(dict(parser.items('cache'))) whois = caching.wrap_whois(cache, uwhois.whois) except: # pylint: disable-msg=W0703 logger.exception("Could not parse config file") return 1 else: net.start_service(iface, port, whois) return 0
def create_uwhois(): """Prepare a UWhois object for testing.""" config = path.join(HERE, '..', 'extra', 'uwhoisd.ini') parser = make_config_parser(config) uwhois = uwhoisd.UWhois() uwhois.read_config(parser) return uwhois
def main(): """ Driver for scraper. """ args = make_arg_parser().parse_args() logging.basicConfig(stream=sys.stderr, level=logging.getLevelName(args.log.upper())) parser = utils.make_config_parser(args.config) whois_servers = {} if args.full else parser.get_section_dict('overrides') for zone, whois_server in scrape_whois_from_iana(ROOT_ZONE_DB, whois_servers): whois_servers[zone] = whois_server print('[overrides]') for zone in sorted(whois_servers): print('%s=%s' % (zone, whois_servers[zone])) if args.ipv4: print('[ipv4_assignments]') for prefix, whois_server in fetch_ipv4_assignments(IPV4_ASSIGNMENTS): print("%s=%s" % (prefix, whois_server)) logging.info("Done") return 0
def main(): """ Execute the daemon. """ if len(sys.argv) != 2: print >> sys.stderr, USAGE % os.path.basename(sys.argv[0]) return 1 logging.config.fileConfig(sys.argv[1]) try: logger.info("Reading config file at '%s'", sys.argv[1]) parser = utils.make_config_parser(CONFIG, sys.argv[1]) iface = parser.get('uwhoisd', 'iface') port = parser.getint('uwhoisd', 'port') logger.info("Listen on %s:%d", iface, port) uwhois = UWhois() uwhois.read_config(parser) if parser.has_section('cache'): logger.info("Caching activated") cache = utils.Cache( max_size=parser.getint('cache', 'max_size'), max_age=parser.getint('cache', 'max_age')) def whois(query): """Caching wrapper around UWhois.""" cache.evict_expired() if query in cache: logger.info("Cache hit for %s", query) response = cache[query] else: response = uwhois.whois(query) cache[query] = response return response else: logger.info("Caching deactivated") whois = uwhois.whois except Exception, ex: # pylint: disable-msg=W0703 print >> sys.stderr, "Could not parse config file: %s" % str(ex) return 1