Home >Backend Development >Python Tutorial >使用python实现扫描端口示例

使用python实现扫描端口示例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-16 08:44:411193browse

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

        if activeCount()

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

            i = i + 1

    while True:

        if activeCount() == 2:

            break

    input('Finished scanning.')

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn