OSError: [WinError 10022] An invalid argument was supplied
Question: Im making a port scanner it through's this message here is my code but it
checks one port 21 i have pasted output below

    
    
    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
    

* * *

On command line :

    
    
    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
    


Answer: You are passing the literal string `'host'` as the host. You should be passing
the variable `host`:

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

You are also not actually closing the socket each time, since you left off the
parentheses in `s.close()`. But if you did close the socket each time, you
would have to create a new socket each time, instead of trying to reuse the
same socket. You can't reuse a closed socket.

