使用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.')

相关文章

PyTorch 1.0 正式版已经发布了

PyTorch 1.0 同时面向产品化 AI 和突破性研究的发展,「我们在 PyTorch1.0 发布前解决了几大问题,包括可重用、性能、编程语言和可扩展性。」Facebook 人工智能...

基于python批量处理dat文件及科学计算方法详解

基于python批量处理dat文件及科学计算方法详解

摘要:主要介绍一些python的文件读取功能,文件内容修改,文件名后缀更改等操作。 批处理文件功能 import os path1 = 'C:\\Users\\awake_ljw\\...

python中将一个全部为int的list 转化为str的list方法

假设有这样一个List [1,2,3,4,5] 转化为下面这个样子 [‘1','2','3','4','5'] 解决方法一: a = [1,2,3] b = [ str(i) for...

python3.4 将16进制转成字符串的实例

将socket收到的16进制转成字符串 def hex_to_str(b): s = '' for i in b: s += '{0:0>2}'.format...

python 实现对数据集的归一化的方法(0-1之间)

多数情况下,需要对数据集进行归一化处理,再对数据进行分析 #首先,引入两个库 ,numpy,sklearn from sklearn.preprocessing import Mi...