Exemple #1
0
    async def https_check(self, ip: IPData, session) -> IPData:
        """
        HTTPS 可用性检测
        :return:
        """
        try:
            async with session.get(self.NORMAL_CHECK_URL.replace(
                    'http', 'https', 1),
                                   proxy=ip.to_http()) as resp:
                result = await resp.json()
                if not result.get('origin'):
                    raise ValidationFailException()
                ip.https = True
        except Exception:
            ip.https = False

        return ip
Exemple #2
0
    async def http_check(self, ip: IPData, session) -> IPData:
        """
        可用与匿名检测 毫秒
        :param ip:
        :return:
        """
        time_spend = datetime.datetime.now()
        try:
            async with session.get(self.NORMAL_CHECK_URL,
                                   proxy=ip.to_http()) as resp:
                result = await resp.json()
                if not result.get('origin'):
                    raise ValidationFailException()
                time_spend = datetime.datetime.now() - time_spend
                ip.delay = time_spend.total_seconds()
                ip.http = True
        except Exception:
            ip.http = False

        return ip
Exemple #3
0
 async def rules_check(self, ip: IPData, session) -> IPData:
     """
     通过规则进行检测
     :return:
     """
     rules = {}
     for rule in Config.RULES:
         assert isinstance(rule, RuleData), 'Error rule format'
         if not rule.enable:
             continue
         try:
             async with session.get(rule.url, proxy=ip.to_http()) as resp:
                 result = await resp.text()
                 assert isinstance(result, str)
                 if rule.contains and result.find(rule.contains) < 0:
                     raise ValidationFailException()
                 rules[rule.key] = True
         except Exception:
             rules[rule.key] = False
     ip.rules = rules
     return ip