【问题标题】:OSError: [WinError 10022] An invalid argument was suppliedOSError: [WinError 10022] 提供的参数无效
【发布时间】:2015-08-01 19:15:47
【问题描述】:

我正在做一个端口扫描器,这条消息是我的代码,但它会检查一个端口 21,我在下面粘贴了输出

import socket
import os
host = input("Enter the host name or ip : ")
s = socket.socket()
s.settimeout(5)
p = 0;
s.close
port = [21,22,23,25,53,80,110,115,135,139,143,194,443,445,1433,3306,3389,5632,5900,6112]
while(p<=19):
    try:
        s.connect(('host', port[p]))
    except ConnectionRefusedError:
        print("Port %d is close" %(port[p]))
    except socket.timeout:
        print("Port %d is close" %(port[p]))
    else:
        print("Port %d is open" %(port[p]))
    p=p+1;
    s.close

在命令行:

PS E:\Codes by me\Selenium py> python .\practice.py
Enter the host name or ip : 89.86.98.76
Port 21 is close # it checks one port
Traceback (most recent call last):
  File ".\practice.py", line 11, in <module>
    s.connect((host, port[p]))
OSError: [WinError 10022] An invalid argument was supplied

【问题讨论】:

    标签: python sockets


    【解决方案1】:

    您将文字字符串 'host' 作为主机传递。你应该传递变量host:

    s.connect((host, port[p]))
    

    您实际上也不是每次都关闭套接字,因为您在s.close() 中省略了括号。但是,如果您每次都关闭套接字,则每次都必须创建一个新套接字,而不是尝试重用同一个套接字。您不能重复使用已关闭的套接字。

    【讨论】:

      猜你喜欢
      • 2017-09-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 2020-12-30
      • 2017-03-19
      • 2016-08-12
      • 1970-01-01
      • 2022-08-23
      相关资源
      最近更新 更多