예제 #1
0
class Request(TestCase):
    def setUp(self):
        proxy = [
            ('http', 'http://202.109.163.75:8085'),
            ('http', 'http://10.10.1.1:123')
        ]
        self.r = Req(proxy_list=proxy, verify_proxy=True)

    def test_proxy_verify(self):
        verify_proxy = [
            {'http': 'http://10.1.111.110:3102'}
        ]
        assert self.r.proxy_list == verify_proxy

    def test_request(self):
        r = Req()
        req = r.request('GET', 'http://www.qq.com')
        assert req.status_code == 200

    def test_request_timeout(self):
        self.r = Req(timeout=0.1)
        try:
            self.r.request('GET', 'http://www.google.com')
        except requests.exceptions.ConnectionError:
            assert True
        else:
            assert False
예제 #2
0
 def test_request_timeout(self):
     self.r = Req(timeout=0.1)
     try:
         self.r.request('GET', 'http://www.google.com')
     except requests.exceptions.ConnectionError:
         assert True
     else:
         assert False
예제 #3
0
def start(args):
    global output_file
    global output_format
    global domain
    global plugin_controller
    domain = args.target
    domain_type = get_domain_type(domain)
    if domain_type in settings.ALLOW_INPUTS:
        domain = Domain.url_format(domain)

        # 初始化日志
        log_level = get_log_level(args.log_level)
        init_logger(log_file_path=args.log_file, log_level=log_level)
        logger.info('system init...')
        # 初始化配置
        conf.settings = settings
        conf.max_level = args.max_level
        output_file = args.output_file
        output_format = args.output_format
        # 初始化爬虫
        proxy_list = get_proxy_list_by_file(args.proxy_file)
        api.request = Req(args.timeout, proxy_list, args.verify_proxy)

        plugin_controller = PluginController()
        plugin_controller.plugin_init()
        logger.info('Loaded plugins: %s' % ','.join(conf.plugins.keys()))

        # 绑定信号事件
        signal.signal(signal.SIGUSR1, on_signal)
        signal.signal(signal.SIGTERM, on_signal)
        signal.signal(signal.SIGINT, on_signal)

        logger.info('start target...')
        # 首个目标
        first_target = {
            'result': {
                'root_domain': [],
                'domain': [],
                'ip': []
            },
            'module': '',
            'level': 0,
            'parent_domain': ''
        }
        first_target['result'][domain_type].append(domain)
        plugin_controller.wp.result.put(first_target)

        # 开启任务监控
        logger.info('start task monitor and plugin...')
        kwargs = {'pc': plugin_controller}
        monitor = threading.Thread(target=task_monitor, kwargs=kwargs)
        monitor.start()

        # 开启插件执行
        plugin_controller.start()

        complate()
    else:
        logger.error('Please input a target in the correct'
                     ' format(domain/root_domain/ip)!')
예제 #4
0
 def test_request_timeout(self):
     self.r = Req(timeout=0.1)
     try:
         self.r.request('GET', 'http://www.google.com')
     except requests.exceptions.ConnectionError:
         assert True
     else:
         assert False
예제 #5
0
class Request(TestCase):
    def setUp(self):
        proxy = [('http', 'http://202.109.163.75:8085'),
                 ('http', 'http://10.10.1.1:123')]
        self.r = Req(proxy_list=proxy, verify_proxy=True)

    def test_proxy_verify(self):
        verify_proxy = [{'http': 'http://10.1.111.110:3102'}]
        assert self.r.proxy_list == verify_proxy

    def test_request(self):
        r = Req()
        req = r.request('GET', 'http://www.qq.com')
        assert req.status_code == 200

    def test_request_timeout(self):
        self.r = Req(timeout=0.1)
        try:
            self.r.request('GET', 'http://www.google.com')
        except requests.exceptions.ConnectionError:
            assert True
        else:
            assert False
예제 #6
0
def start():
    conf.domain = options.target
    domain_type = get_domain_type(conf.domain)
    if domain_type in settings.ALLOW_INPUTS:
        conf.domain = Domain.url_format(conf.domain)

        # 初始化日志
        log_level = get_log_level(options.log_level)
        init_logger(log_file_path=options.log_file, log_level=log_level)
        api.logger.info('System init at %s' % time.strftime("%X"))
        # 初始化配置
        conf.settings = settings
        # 初始化爬虫
        proxy_list = get_proxy_list_by_file(options.proxy_file)
        api.request = Req(options.timeout, proxy_list, options.verify_proxy)

        conf.plugin_controller = PluginController()
        conf.plugin_controller.plugin_init(options.plugins_specific)
        api.logger.info('Loaded plugins: %s' %
                        ', '.join(conf.plugins_load.keys()))

        # 绑定信号事件
        if hasattr(signal, 'SIGUSR1'):
            signal.signal(signal.SIGUSR1, on_signal)
        signal.signal(signal.SIGTERM, on_signal)
        signal.signal(signal.SIGINT, on_signal)

        api.logger.info('Start target [%s]' % conf.domain)
        # 首个目标
        first_target = {
            'result': {
                'root_domain': [],
                'domain': [],
                'ip': []
            },
            'module': '',
            'level': 0,
            'parent_domain': ''
        }
        first_target['result'][domain_type].append(conf.domain)
        conf.plugin_controller.wp.result.put(first_target)

        # 开启任务监控
        api.logger.info('Start task monitor and plugin...')
        kwargs = {'pc': conf.plugin_controller}
        monitor = threading.Thread(target=task_monitor, kwargs=kwargs)
        monitor.start()

        # 开启插件执行
        conf.plugin_controller.start()

        if options.alive_check:
            alivecheck = AliveCheck()
            print '\n'
            api.logger.info('Init alive check...')
            alivecheck.start()
            api.logger.info('Alive check completed')

        complete()
    else:
        api.logger.error('Please input a target in the correct'
                         ' format(domain/root_domain/ip)!')
예제 #7
0
 def test_request(self):
     r = Req()
     req = r.request('GET', 'http://www.qq.com')
     assert req.status_code == 200
예제 #8
0
 def setUp(self):
     proxy = [('http', 'http://202.109.163.75:8085'),
              ('http', 'http://10.10.1.1:123')]
     self.r = Req(proxy_list=proxy, verify_proxy=True)
예제 #9
0
 def test_request(self):
     r = Req()
     req = r.request('GET', 'http://www.qq.com')
     assert req.status_code == 200
예제 #10
0
 def setUp(self):
     proxy = [
         ('http', 'http://202.109.163.75:8085'),
         ('http', 'http://10.10.1.1:123')
     ]
     self.r = Req(proxy_list=proxy, verify_proxy=True)