# power by 墨天逸 import socket target = input("请输入您的扫描目标IP地址:") targetIP = socket.gethostbyname(target) print ("开始扫描目标-",targetIP) for port in range(1,65535): try: server = socket.socket(socket.AF_INET,socket.SOCK_STREAM) server.settimeout(2) result = server.connect((targetIP,port)) if (result == 0): print ("Port %d is open"%port) else: print ("Port %d is close"%port) server.close() except socket.error: print ("Connect",targetIP, port,"Faild!") print ("本次扫描已结束")
Python 简记 socket端口扫描,挺好用的!