yl6688

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
from socket import *

import time

startTime = time.time()



target = input('需要扫描的主机: ')

t_IP = gethostbyname(target)

print('开始扫描主机: ', t_IP)

for i in range(100, 65535):

    print('当前正扫描端口号:'+str(i))

# 创建 socket 对象

    s = socket(AF_INET, SOCK_STREAM)

# socket.connect_ex(IP,port),如果端口连接成功 则返回 0

    conn = s.connect_ex((t_IP, i))

    if (conn == 0):

        print('端口 %d: 处于开放状态' % (i,))

        s.close()

 

posted on 2023-03-05 15:01  追梦寒星  阅读(21)  评论(0编辑  收藏  举报