async def start_check(self): with await Redis.share() as redis: ip_str = await redis.blpop(Config.REDIS_KEY_CHECK_POOL) ip_str = ip_str[1].decode() Logger.info('[check] got ip %s' % ip_str) Prometheus.IP_CHECK_TOTAL.inc(1) ip = IPData.with_str(ip_str) async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout( Config.DEFAULT_REQUEST_CHECK_TIME_OUT)) as session: ip = await self.http_check(ip, session) ip = await self.https_check(ip, session) ip = await self.rules_check(ip, session) Logger.info( '[check] Check result %s http %s https %s %s', ip.to_str(), ip.http, ip.https, " ".join(["%s %s" % (k, r) for k, r in ip.rules.items()])) await IPSaver().save_ip(ip)
async def get_ips(cls, http: bool = True, https: bool = False, delay: int = None, rule: str = None): keys = [] if http: keys.append(Config.REDIS_KEY_ABLE_HTTP) if https: keys.append(Config.REDIS_KEY_ABLE_HTTPS) if delay: keys.append(Config.REDIS_KEY_NET_DELAY % delay) if rule: keys.append(Config.REDIS_KEY_ABLE_RULES % rule) with await Redis.share() as redis: ips = await redis.sinter(*keys) ips = [IPData.with_str(ip.decode()) for ip in ips] return ips