Beispiel #1
0
    def req_scan_ip_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ""
        if reqs['cmd'] == ['get_range']:
            data = ip_range.load_range_content()
        elif reqs['cmd'] == ['set_range']:
            content = self.postvars['ip_range'][0]
            ip_range.update_range_content(content)
            ip_range.load_ip_range()
            data = '{"res":"success"}'
        elif reqs['cmd'] == ['set_auto_adjust_scan_ip_thread_num']:
            user_config.user_special.auto_adjust_scan_ip_thread_num = int(self.postvars['auto_adjust_scan_ip_thread_num'][0])
            user_config.save()

            google_ip.auto_adjust_scan_ip_thread_num = user_config.user_special.auto_adjust_scan_ip_thread_num
            data = '{"res":"success"}'
        elif reqs['cmd'] == ['set_scan_thread_num']:
            user_config.user_special.scan_ip_thread_num = int(self.postvars['scan_ip_thread_num'][0])
            user_config.save()

            scan_ip_thread_num = int(self.postvars['scan_ip_thread_num'][0])
            google_ip.adjust_scan_thread_num(scan_ip_thread_num)
            data = '{"res":"success"}'
        elif reqs['cmd'] == ['get_scan_ip_log']:
            data = scan_ip_log.get_log_content()

        mimetype = 'text/plain'
        self.send_response(mimetype, data)
Beispiel #2
0
    def req_scan_ip_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ""
        if reqs['cmd'] == ['get_range']:
            data = ip_range.load_range_content()
        elif reqs['cmd'] == ['set_range']:
            content = self.postvars['ip_range'][0]
            ip_range.update_range_content(content)
            ip_range.load_ip_range()
            data = '{"res":"success"}'
        elif reqs['cmd'] == ['set_auto_adjust_scan_ip_thread_num']:
            user_config.user_special.auto_adjust_scan_ip_thread_num = int(
                self.postvars['auto_adjust_scan_ip_thread_num'][0])
            user_config.save()

            google_ip.auto_adjust_scan_ip_thread_num = user_config.user_special.auto_adjust_scan_ip_thread_num
            data = '{"res":"success"}'
        elif reqs['cmd'] == ['set_scan_thread_num']:
            user_config.user_special.scan_ip_thread_num = int(
                self.postvars['scan_ip_thread_num'][0])
            user_config.save()

            scan_ip_thread_num = int(self.postvars['scan_ip_thread_num'][0])
            google_ip.adjust_scan_thread_num(scan_ip_thread_num)
            data = '{"res":"success"}'
        elif reqs['cmd'] == ['get_scan_ip_log']:
            data = scan_ip_log.get_log_content()

        mimetype = 'text/plain'
        self.send_response(mimetype, data)
Beispiel #3
0
    def scan_ip_worker(self):
        while self.scan_thread_count <= self.scan_ip_thread_num and connect_control.keep_running:
            if not connect_control.allow_scan():
                time.sleep(10)
                continue

            try:
                time.sleep(1)
                ip = self.ip_range.get_ip()

                if ip in self.ip_dict:
                    continue

                result = check_ip.test_gae_ip2(ip)
                if not result or not result.support_gae:
                    continue

                if self.add_ip(ip, result.handshake_time, result.domain, "gws"):
                    #xlog.info("add  %s  CN:%s  type:%s  time:%d  gws:%d ", ip,
                    #     result.domain, result.server_type, result.handshake_time, len(self.gws_ip_list))
                    xlog.info("scan_ip add ip:%s time:%d", ip, result.handshake_time)
                    if config.log_scan:
                        import re
                        log = scan_ip_log.get_log_content()
                        log_ip = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',re.S).findall(log)
                        if ip not in log_ip:
                            scan_ip_log.info("Add %s time:%d CN:%s ", ip, result.handshake_time, result.domain)
                    self.remove_slowest_ip()
                    self.save_ip_list()
            except Exception as e:
                xlog.exception("google_ip.runJob fail:%r", e)

        self.scan_thread_lock.acquire()
        self.scan_thread_count -= 1
        self.scan_thread_lock.release()
Beispiel #4
0
    def scan_ip_worker(self):
        while self.scan_thread_count <= self.scan_ip_thread_num and connect_control.keep_running:
            if not connect_control.allow_scan():
                time.sleep(10)
                continue

            try:
                time.sleep(1)
                ip = google_ip_range.ip_range.get_ip()

                if ip in self.ip_dict:
                    continue

                result = check_ip.test_gae_ip2(ip)
                if not result or not result.support_gae:
                    continue

                if self.add_ip(ip, result.handshake_time, result.domain, "gws"):
                    #xlog.info("add  %s  CN:%s  type:%s  time:%d  gws:%d ", ip,
                    #     result.domain, result.server_type, result.handshake_time, len(self.gws_ip_list))
                    xlog.info("scan_ip add ip:%s time:%d", ip, result.handshake_time)
                    if config.log_scan:
                        import re
                        log = scan_ip_log.get_log_content()
                        log_ip = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}',re.S).findall(log)
                        if ip not in log_ip:
                            scan_ip_log.info("Add %s time:%d CN:%s ", ip, result.handshake_time, result.domain)
                    self.remove_slowest_ip()
                    self.save_ip_list()
            except Exception as e:
                xlog.exception("google_ip.runJob fail:%r", e)

        self.scan_thread_lock.acquire()
        self.scan_thread_count -= 1
        self.scan_thread_lock.release()
Beispiel #5
0
    def req_scan_ip_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ""
        if reqs['cmd'] == ['get_range']:
            data = ip_range.load_range_content()

        elif reqs['cmd'] == ['update']:
            #update ip_range if needed
            content = self.postvars['ip_range'][0]

            #check ip_range checksums, update if needed
            default_digest = hashlib.md5(
                ip_range.load_range_content(default=True)).hexdigest()
            old_digest = hashlib.md5(ip_range.load_range_content()).hexdigest()
            new_digest = hashlib.md5(content).hexdigest()

            if new_digest == default_digest:
                ip_range.remove_user_range()

            else:
                if old_digest != new_digest:
                    ip_range.update_range_content(content)

            if old_digest != new_digest:
                ip_range.load_ip_range()

            #update auto_adjust_scan_ip and scan_ip_thread_num
            should_auto_adjust_scan_ip = int(
                self.postvars['auto_adjust_scan_ip_thread_num'][0])
            thread_num_for_scan_ip = int(
                self.postvars['scan_ip_thread_num'][0])

            use_ipv6 = self.postvars['use_ipv6'][0]
            if user_config.user_special.use_ipv6 != use_ipv6:
                xlog.debug("use_ipv6 change to %s", use_ipv6)
                user_config.user_special.use_ipv6 = use_ipv6

            #update user config settings
            user_config.user_special.auto_adjust_scan_ip_thread_num = should_auto_adjust_scan_ip
            user_config.user_special.scan_ip_thread_num = thread_num_for_scan_ip
            user_config.save()
            config.load()

            #update google_ip settings
            google_ip.auto_adjust_scan_ip_thread_num = should_auto_adjust_scan_ip

            if google_ip.max_scan_ip_thread_num != thread_num_for_scan_ip:
                google_ip.adjust_scan_thread_num(thread_num_for_scan_ip)

            #reponse
            data = '{"res":"success"}'

        elif reqs['cmd'] == ['get_scan_ip_log']:
            data = scan_ip_log.get_log_content()

        mimetype = 'text/plain'
        self.send_response_nc(mimetype, data)
Beispiel #6
0
    def req_scan_ip_handler(self):
        req = urlparse.urlparse(self.path).query
        reqs = urlparse.parse_qs(req, keep_blank_values=True)
        data = ""
        if reqs['cmd'] == ['get_range']:
            data = ip_range.load_range_content()

        elif reqs['cmd'] == ['update']:
            #update ip_range if needed
            content = self.postvars['ip_range'][0]

            #check ip_range checksums, update if needed
            default_digest = hashlib.md5(ip_range.load_range_content(default=True)).hexdigest()
            old_digest = hashlib.md5(ip_range.load_range_content()).hexdigest()
            new_digest = hashlib.md5(content).hexdigest()

            if new_digest == default_digest:
                ip_range.remove_user_range()

            else:
                if old_digest != new_digest:
                    ip_range.update_range_content(content)

            if old_digest != new_digest:
                ip_range.load_ip_range()

            #update auto_adjust_scan_ip and scan_ip_thread_num
            should_auto_adjust_scan_ip = int(self.postvars['auto_adjust_scan_ip_thread_num'][0])
            thread_num_for_scan_ip = int(self.postvars['scan_ip_thread_num'][0])

            use_ipv6 = self.postvars['use_ipv6'][0]
            if user_config.user_special.use_ipv6 != use_ipv6:
                xlog.debug("use_ipv6 change to %s", use_ipv6)
                user_config.user_special.use_ipv6 = use_ipv6

            #update user config settings
            user_config.user_special.auto_adjust_scan_ip_thread_num = should_auto_adjust_scan_ip
            user_config.user_special.scan_ip_thread_num = thread_num_for_scan_ip
            user_config.save()
            config.load()

            #update google_ip settings
            google_ip.auto_adjust_scan_ip_thread_num = should_auto_adjust_scan_ip

            if google_ip.max_scan_ip_thread_num != thread_num_for_scan_ip:
                google_ip.adjust_scan_thread_num(thread_num_for_scan_ip)

            #reponse 
            data='{"res":"success"}'

        elif reqs['cmd'] == ['get_scan_ip_log']:
            data = scan_ip_log.get_log_content()

        mimetype = 'text/plain'
        self.send_response_nc(mimetype, data)