使用python实现扫描端口示例

yipeiwu_com6年前Python基础

python最简洁易懂的扫描端口代码.运行绝对会很有惊奇感

复制代码 代码如下:

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 设置输出图像的像素大小方法

如下所示: plt.rcParams['savefig.dpi'] = 300 #图片像素 plt.rcParams['figure.dpi'] = 300 #分辨率 为了记住不...

Python中的yield浅析

在介绍yield前有必要先说明下Python中的迭代器(iterator)和生成器(constructor)。 一、迭代器(iterator) 在Python中,for循环可以用于Pyt...

python模拟实现斗地主发牌

题目:趣味百题之斗地主 扑克牌是一种非常大众化的游戏,在计算机中有很多与扑克牌有关的游戏。例如,在Windows操作系统下自带的纸牌、红心大战等。在扑克牌类的游戏中,往往都需要执行洗牌操...

Python命令行解析模块详解

本文研究的主要是Python命令行解析模块的相关内容,具体如下。 Python命令行常见的解析器有两种,一是getopt模块,二是argparse模块。下面就解读下这两种解析器。 ge...

python 读取文件并把矩阵转成numpy的两种方法

在当前目录下: 方法1: file = open(‘filename') a =file.read() b =a.split(‘\n')#使用换行 len(b) #统计有多少行...