def multi_target_test(options, target): # 删除文件 tem_dir = os.getcwd() + "\\tmp\\" if os.path.exists(tem_dir): shutil.rmtree(tem_dir) tmp_dir = os.getcwd() + '//tmp/%s_%s' % (target, int(time.time())) if not os.path.exists(tmp_dir): # 生成路径 os.makedirs(tmp_dir) multiprocessing.freeze_support() all_process = [] dns_servers = load_dns_servers() # 载入DNS服务器 next_subs = load_next_sub(options) scan_count = multiprocessing.Value('i', 0) found_count = multiprocessing.Value('i', 0) queue_size_list = multiprocessing.Array('i', options.process) try: print '[+] Init %s scan process.' % options.process for process_num in range(options.process): p = multiprocessing.Process( target=run_process, args=(target, options, process_num, dns_servers, next_subs, scan_count, found_count, queue_size_list, tmp_dir)) all_process.append(p) p.start() while all_process: for p in all_process: if not p.is_alive(): all_process.remove(p) # 如果进程结束就退出 groups_count = 0 for c in queue_size_list: groups_count += c msg = '[*] %s found, %s scanned in %.1f seconds, %s groups left' % ( found_count.value, scan_count.value, time.time() - start_time, groups_count) print_msg(msg) time.sleep(1.0) except KeyboardInterrupt as e: for p in all_process: p.terminate() print '[ERROR] User aborted the scan!' except Exception as e: print e msg = '[+] All Done. %s found, %s scanned in %.1f seconds.' % ( found_count.value, scan_count.value, time.time() - start_time) print_msg(msg, line_feed=True) out_file_name = get_out_file_name(target, options) # 输出路径位置 with open(out_file_name, 'w') as f: for _file in glob.glob(tmp_dir + '/*.txt'): with open(_file, 'r') as tmp_f: content = tmp_f.read() f.write(content) # 删除文件 shutil.rmtree(tem_dir) print '[+] The output file is %s' % out_file_name
s.run() if __name__ == '__main__': options, args = parse_args() start_time = time.time() # make tmp dirs tmp_dir = 'tmp/%s_%s' % (args[0], int(time.time())) if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) multiprocessing.freeze_support() all_process = [] dns_servers = load_dns_servers() cdns = load_cdn_domains() next_subs = load_next_sub(options) scan_count = multiprocessing.Value('i', 0) found_count = multiprocessing.Value('i', 0) queue_size_list = multiprocessing.Array('i', options.process) try: print '[+] Init %s scan process.' % options.process for process_num in range(options.process): p = multiprocessing.Process(target=run_process, args=(args[0], options, process_num, dns_servers, next_subs, scan_count, found_count,queue_size_list, tmp_dir,cdns) ) all_process.append(p) p.start()
tmp_dir=tmp_dir) s.run() if __name__ == '__main__': options, args = parse_args() start_time = time.time() # make tmp dirs tmp_dir = 'tmp/%s_%s' % (args[0], int(time.time())) if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) multiprocessing.freeze_support() all_process = [] dns_servers = load_dns_servers() next_subs = load_next_sub(options) scan_count = multiprocessing.Value('i', 0) found_count = multiprocessing.Value('i', 0) queue_size_list = multiprocessing.Array('i', options.process) try: print '[+] Init %s scan process.' % options.process for process_num in range(options.process): p = multiprocessing.Process(target=run_process, args=(args[0], options, process_num, dns_servers, next_subs, scan_count, found_count,queue_size_list, tmp_dir) ) all_process.append(p) p.start()