做个学习笔记,若有错误,望指出
转载自:https://www.jb51.net/article/86615.htm
import socket
import threading
def scan(port):
s = socket.socket()
s.settimeout(0.1)
#print(port)
if s.connect_ex(('localhost', port)) == 0:
print(port, 'open')
s.close()
#不允许import到其他脚本中执行
if __name__ == "__main__":
#map() 会根据提供的函数对指定序列做映射,需转list才能执行
threads=[threading.Thread(target=scan,args=(i,)) for i in range(1,65536)]
list(map(lambda x:x.start(),threads))