您的位置:首页 > 编程语言 > Python开发

使用python实现扫描端口示例

2014-03-29 09:22 826 查看
from threading import Thread, activeCount

import socket

import os

def test_port(dst,port):

    os.system('title '+str(port))    cli_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:        indicator = cli_sock.connect_ex((dst, port))

        if indicator == 0:

            print(port)

        cli_sock.close()

    except:        pass

if __name__=='__main__':

    dst = '192.168.0.22'    i = 0

    while i < 65536:

        if activeCount() <= 200:

            Thread(target = test_port, args = (dst, i)).start()            i = i + 1

    while True:

        if activeCount() == 2:            break    input('Finished scanning.')

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 端口