国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

python多線程掃描端口示例

2020-02-23 05:05:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

代碼如下:
# -*- coding: cp936 -*-
import socket
from threading import Thread,activeCount,Lock
from time import ctime
mutex = Lock()

class Loop(Thread):
    def __init__(self,ip,port,que):
        Thread.__init__(self)
        self.ip     = ip
        self.port   = port
        self.que    = que

    def run(self):
        global mutex
        try:
            client = socket.socket()
            indicator = client.connect_ex((self.ip,self.port))
            if mutex.acquire(1):
                if indicator == 0:
                    que.append(self.ip+'/t'+str(self.port))
                else:
                    print self.ip,'/t',str(self.port),'不可達(dá)'
                mutex.release()
        except:
            if mutex.acquire(1):
                print self.ip,'/t',str(self.port),'不可達(dá)'
                mutex.release()

class Main(Thread):
    def __init__(self,ip,que):
        Thread.__init__(self)
        self.ip  = ip
        self.que = que

    def run(self):
        i = 0
        while i < 65536:
            if activeCount() <= 200:
                Loop(ip=self.ip,port=i,que=self.que).start()
                i = i + 1

if __name__ == '__main__':
    que = []
    ip = raw_input('IP=')

    main = Main(ip = ip,que = que)
    main.start()

    while True:
        if activeCount() <= 1 and main.isAlive() == False:

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 黄浦区| 天等县| 合江县| 中阳县| 武义县| 甘洛县| 西青区| 开阳县| 定兴县| 米林县| 阿勒泰市| 岳西县| 浦江县| 哈密市| 苍溪县| 扎兰屯市| 静宁县| 浦城县| 会昌县| 武汉市| 连城县| 宜川县| 宝兴县| 中西区| 淮滨县| 嘉善县| 洱源县| 晋中市| 蒙自县| 元氏县| 铜山县| 景德镇市| 施秉县| 江川县| 江孜县| 长乐市| 镇安县| 育儿| 玉山县| 灵台县| 油尖旺区|