Simple port scanner in Python 3
Connections

You don't close your sockets and connections. The best way to ensure you close them is with a context manager (with-statement)

You can also reuse the socket you make, and connect it to other ports. This would make a SocketConnection:

class SocketConnection:
    def init(self, ip, port=None):
        self.socket = None
        self.ip = ip    

    def __enter__(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def __exit__(self, type, value, traceback):
        self.socket.close()
        self.socket = None

    def portscan(self, port):
        if self.socket is None:
            raise ConnectionError('No socket open')
        try:
            return not self.socket.connect_ex((self.ip, port))
        finally:
            self.socket.detach()


This can be used like this:

def scan_ports(ip, port_range):
    """yields the open ports in `port_range` (port_range is half-open) """
    with SocketConnection(ip) as connection:
        for port in range(*ports):
            if connection.portscan(port):
                yield port


Validate input

You don't validate the input of your client. To do this, you can do something like this:

def validate_ip(ip):
    return True # needs implementation
def get_ip():
    while True:
        ip = input("Target IP: ")
        if validate_ip(ip):
            return ip


You can do ctrl+C to get out of this while True loop

and then the main() function:

def main():
    logging.basicConfig(filename="errlog.log", format="%(asctime)s : %(message)s")
    logging.info("Start")
    message = """
    Hello user and welcome to Network Port Scanner!
    Please insert a IP address that you want to scan for open and closed ports.
    The range of ports scanned is 1-65535.
    """
    print(message)
    ip = get_ip()
    open_ports = list(scan_ports(ip, (1, 65536)))

    print(
        f"""open ports: ({len(open_ports)})
        {open_ports}""")


Caveat: I don't know a lot about socket programming. I just used the python documentation, so there might be socket-related bugs