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()
标签:socket,端口扫描,IP,Python,time,print,检测工具 From: https://www.cnblogs.com/yl6688/p/17180615.html