Python中telnetlib中open()函数的用法

时间:2017-05-23 06:08:40

标签: python linux sockets telnet

我不太明白telnetlib中的open()函数,有人可以帮我解释一下吗?

def open(self, host, port=0):
        """Connect to a host.

        The optional second argument is the port number, which
        defaults to the standard telnet port (23).

        Don't try to reopen an already connected instance.

        """
        self.eof = 0
        if not port:
            port = TELNET_PORT
        self.host = host
        self.port = port
        msg = "getaddrinfo returns an empty list"
    # ---
        for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res  #???
            try:
                self.sock = socket.socket(af, socktype, proto)
                self.sock.connect(sa) 
    # ---
            except socket.error, msg:
                if self.sock:
                    self.sock.close()
                self.sock = None
                continue
            break
        if not self.sock:
            raise socket.error, msg

从For到Part除外,我感到很困惑。

此功能是否用于telnet?为什么没有任何telnet?

0 个答案:

没有答案