import socket
import threading
from queue import Queue
import os


port_list = [x for x in range(1, 65536)]


def port_scan(target, port):
    flag = 0
    s_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s_tcp.settimeout(4)
    s_udp.settimeout(4)
    try:
        s_tcp.connect((target, port))
        s_tcp.close()
        flag += 1
    except socket.error:
        pass
    try:
        s_udp.connect((target, port))
        s_udp.close()
        flag += 2
    except socket.error:
        pass
    return flag


def worker(target):
    while work_queue.empty() is False:
        port = work_queue.get()
        try:
            flag = port_scan(target, port)
        finally:
            if flag == 1:
                print("%s:%s tcp" % (target, port), "is open")
            elif flag == 3:
                print("%s:%s tcp/udp" % (target, port), "is open")
            work_queue.task_done()


if __name__ == "__main__":
    target_host = input("input the host:\n")
    work_queue = Queue()
    for element in port_list:
        work_queue.put(element)
    threads = [threading.Thread(target=worker, args=(target_host,)) for i in range(16)]
    for t in threads:
        t.setDaemon(True)
        t.start()
    work_queue.join()
    os.system("pause")
 

@@ -52,18 +52,8 @@
 eue%0A
-import os%0A
 %0A%0Apo
@@ -578,20 +578,159 @@
 g%0A%0A%0Adef 
-work
+producer():%0A    while True:%0A        try:%0A            work_queue.put(port_list.pop(0))%0A        except IndexError:%0A            break%0A%0A%0Adef consum
 er(targe
@@ -1203,81 +1203,170 @@
     
-for element in port_list:%0A        work_queue.put(element)%0A    threads = %5B
+producer_thread = threading.Thread(target=producer)%0A    producer_thread.start()%0A    consumer_threads = %5B%5D%0A    for i in range(16):%0A        consumer_threads.append(
 thre
@@ -1385,20 +1385,22 @@
 (target=
-work
+consum
 er, args
@@ -1419,28 +1419,9 @@
 t,))
- for i in range(16)%5D
+)
 %0A   
@@ -1430,16 +1430,25 @@
 or t in 
+consumer_
 threads:
@@ -1518,29 +1518,4 @@
 n()%0A
-    os.system(%22pause%22)%0A %0A

Update portscanner.py