I am about to write my own portscanner instead of using the python-nmap. The built-in python socket library has this connect_ex() function, from the documentation it says connect_ex() returns 0 if the operation is successful otherwise will return a value to errno variable. What this means is if the connection is successful the method connect_ex() returns 0 otherwise some value will be returned.
This code attempts to connect to a host by port 443, however the host does not have 443 hence it returns this:
So I tried another port which is available:
because 445 is available the code returns this: