当我运行此代码时,我收到此套接字错误:
[WinError 10038] 尝试对非套接字的操作进行操作
但即使我删除s.close()
它也会给我错误的结果。
它是一个端口扫描器,它将尝试连接到我要扫描的服务器上的所有端口。我从中获得连接的那些存储在一个列表中。但由于某种原因,它给了我错误的结果。有人可以帮帮我吗。
import socket
import threading
def scan_for_open_ports():
#Creating variables
OpenPorts = []
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = input('Host to scan: ')
global port
global OpenPorts
port = 1
#Scanning
for i in range(65534):
try:
s.connect((host, port))
s.shutdown(2)
OpenPorts.append(port)
print(str(port) + 'is open.')
s.close()
port += 1
except socket.error as msg:
print(msg)
s.close()
show_user()
def show_user():
#Giving the user results
print('------Open porst-----\n')
print(OpenPorts)