使用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中,不用while和for循环遍历列表的实例

如下所示: a = [1, 2, 3, 8, 9] def printlist(l, index): if index == len(l): return else:...

Python中的time模块与datetime模块用法总结

time模块 time模块是包含各方面对时间操作的函数. 尽管这些常常有效但不是所有方法在任意平台中有效. time用struct_time表示时间 import time # t...

python datetime中strptime用法详解

python 中datetime中strptime用法,具体代码如下所示: import datetime day20 = datetime.datetime.strptime('2...

Python控制多进程与多线程并发数总结

Python控制多进程与多线程并发数总结

一、前言 本来写了脚本用于暴力破解密码,可是1秒钟尝试一个密码2220000个密码我的天,想用多线程可是只会一个for全开,难道开2220000个线程吗?只好学习控制线程数了,官方文档...

浅谈python和C语言混编的几种方式(推荐)

Python这些年风头一直很盛,占据了很多领域的位置,Web、大数据、人工智能、运维均有它的身影,甚至图形界面做的也很顺,乃至full-stack这个词语刚出来的时候,似乎就是为了描述它...