I have the following script which just isnt working for me :(. I essentially want to create 10 threads to port scan a range of 100 ports. It should seem simple but I dont know where I am going wrong. Im new to python and have been looking at how to get this working for the past two weeks and I know give up. When executed it just does nothing. Help please :).

EDIT: Updated the code but it now states none when I run it.
 #Import Modules
 from scapy.all import \*
 from Queue import Queue
 from threading import Thread

```
            #Set Variables
            threadCount = 10
            destIP = "192.168.136.131"
            portLength = 100
            q = Queue(maxsize=0)

            #Empty Arrays
            openPorts = []
            closedPorts = []
            threads = []

            def qProcessor(q):
                while True:
                        try:
                            print q.get()
                            #getQ = q.get()
                            #getQ()
                            #if getQ() is None:
                            #   break 
                            #else:
                            q.task_done()
                        except Exception as e:
                            print 'error in qprocessor function'
                            print e

            def portScan(port, dstIP):
                scan = sr1(IP(dst=dstIP)/TCP(dport=port,flags="S"), verbose=0)
                if scan.getlayer(TCP).flags == 0x12:
                    openPorts.append("IP: %s \t Port: %s"%(scan.getlayer(IP).src, scan.getlayer(TCP).sport))
                    sr1(IP(dst=dstIP)/TCP(dport=port,flags="R"),verbose=0)

                if scan.getlayer(TCP).flags == 0x14:
                    closedPorts.append("IP: %s \t Port: %s"%(scan.getlayer(IP).src, scan.getlayer(TCP).sport))

            def main():

                try:
                        for i in range(threadCount):
                                worker = Thread(target=qProcessor, args =(q,))
                                worker.setDaemon(True)
                                worker.start()
                except Exception as e:
                        print "error in worker section"
                        print e

                for p in range(portLength):
                    q.put(portScan(p, destIP))

                q.join()
            if __name__ == '__main__':
                main()

            for port in openPorts:
                print port

```

So i found the answer. This has killed me for two weeks and I ended up debugging the application with the pdb module and the '-v' switch. I have learnt a lot from this exercise and want to kill python after this lol. But working it out with the little hints from stackoverflow has been awesome. Here is the final script. I have commented the line that was giving me issues whilst I work out a way around it. BTW this works fine without threading.

```
            #Import Modules
            from scapy.all import *
            from Queue import Queue
            from threading import Thread

            #Set Variables
            threadCount = 10
            destIP = "192.168.136.131"
            portLength = 100
            q = Queue(maxsize=0)

            #Empty Arrays
            openPorts = []
            closedPorts = []
            threads = []

            def main():
                    try:
                            for i in range(threadCount):
                                    worker = Thread(target=qProcessor, args =(q,))
                                    worker.setDaemon(True)
                                    worker.start()
                    except Exception as e:
                            print "error in worker section"
                            print e

                    for p in range(portLength):
                            q.put(portScan(p, destIP))

                    q.join()

            def qProcessor(q):
                while True:
                        try:
                            q.get()
                            q.task_done()
                        except Exception as e:
                            print 'error in qprocessor function'
                            print e

            def portScan(port, dstIP):
                scan = sr1(IP(dst=dstIP)/TCP(dport=port,flags="S"), verbose=0)
                if scan.getlayer(TCP).flags == 0x12:
                    openPorts.append("IP: %s \t Port: %s"%(scan.getlayer(IP).src, scan.getlayer(TCP).sport))
                #   sr1(IP(dst=dstIP)/TCP(dport=port,flags="R"),verbose=0)

                if scan.getlayer(TCP).flags == 0x14:
                    closedPorts.append("IP: %s \t Port: %s"%(scan.getlayer(IP).src, scan.getlayer(TCP).sport))
                else:
                    pass

            if __name__ == '__main__':
                main()

            for port in openPorts:
                print port

```