python线程端口扫描程序

时间:2016-11-19 04:14:35

标签: python multithreading

当我的应用程序通过所有端口时,它应该打印“完成”。但事实并非如此。这就是我所拥有的:

import time
import socket
import threading
from queue import Queue

printLock = threading.Lock()

q = Queue()

target = input("Enter Ip: ")

def portscan(port):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
       con = s.connect((target,port))
       with printLock:
          print("port",port,"open")
       con.close()
    except:
       pass

def threader():
   while True:
      worker = q.get()
      portscan(worker)
      q.task_done()

for x in range(10000):
   t = threading.Thread(target = threader)
   t.daemon = True
   t.start()

for worker in range(1,101):
   q.put(worker)

q.join()

print("done")

0 个答案:

没有答案