def load_host(args): host_list = [] if args.host: host_list.append(getip(args.host.strip())) color_print.cyan(f"[*] load host to scan: {host_list[0]}") elif args.host_file: try: with open(args.host_file, 'r', encoding='utf-8') as f: for target in f.readlines(): host_list.append(getip(target.strip())) color_print.cyan(f"[*] load host file to scan: {args.host_file}") except Exception as e: color_print.red(f"[-] error host_file: {args.host_file}\n[-] {e}") sys.exit() # exclude empty elements and remove duplicates host_list = list(set(filter(None, host_list))) if len(host_list) < 1: color_print.red(f"[-] no target to scan, use -H/-HF to specify target") sys.exit() return host_list
sys.exit() return host_list if __name__ == "__main__": start_time = time.time() global thread_count args = cmdLineParser() # get host hosts = load_host(args) # get port list ports = [] if args.port: ports = [int(port) for port in args.port.split(',')] color_print.cyan(f"[*] begin to scan ports: {ports}") else: color_print.cyan(f"[*] begin to scan default ports") # generate tasks task_queue = generate_tasks(hosts, ports) color_print.cyan(f"[*] task count:{task_queue.qsize()}") # get thread count thread_count = args.thread if args.thread and args.thread < 200 else 100 if thread_count >= task_queue.qsize(): thread_count = task_queue.qsize() color_print.cyan(f"[*] set thread count: {thread_count}") # run run(task_queue)