python线程端口scann

2024-06-25 06:08:30 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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")

Tags: importtruetargetqueueportdefsocketcon