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
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(args[0], 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) print '[+] The output file is %s' % out_file_name
found_count.value, scan_count.value, time.time() - start_time, groups_count, ) print_msg(msg) count += 1 time.sleep(0.3) except KeyboardInterrupt as e: print("[ERROR] User aborted the scan!") for p in all_process: p.terminate() except Exception as e: print("[ERROR] %s" % str(e)) out_file_name = get_out_file_name(domain, options) all_domains = set() domain_count = 0 with open(out_file_name, "w") as f: for _file in glob.glob(tmp_dir + "/*.txt"): with open(_file, "r") as tmp_f: for domain in tmp_f: if domain not in all_domains: domain_count += 1 all_domains.add( domain ) # cname query can result in duplicated domains f.write(domain) msg = "All Done. %s found, %s scanned in %.1f seconds." % ( domain_count,
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(domain.strip(), options) #这里改了生成路径方便压缩下载 with open('result/' + 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) print '[+] The output file is %s' % out_file_name
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(args[0], 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) print '[+] The output file is %s' % out_file_name