Telnet

Telnet is an old protocol, specified by RFC 854 (see http://www.ietf.org/rfc/rfc854.txt), and is normally used for interactive user sessions. The Python standard library supports this protocol in its module telnetlib. Module telnetlib supplies a class Telnet to connect to a Telnet server.

Telnet

class Telnet(host=None,port=23)

Returns an instance t of class Telnet. When host (and optionally port) is given, implicitly calls t.open(host,port).

Instance t supplies many methods, of which the most frequently used are as follows.

close

t.close( )

Closes the connection.

expect

t.expect(res,timeout=None)

Reads data from the connection until it matches any of the regular expressions that are the items of list res, or until timeout seconds elapse when timeout is not None. (Regular expressions and match objects are covered in Regular Expressions and the re Module.) Returns a tuple of three items (i,mo,txt), where i is the index in res of the regular expression that matched, mo is the match object, and txt is all the text read until the match, included. Raises EOFError when the connection is closed and no data is available; otherwise, when it gets no match, returns (-1,None,txt), where txt is all the text read, or possibly '' if nothing was read before a timeout. Results are nondeterministic if more than one item in res can match, or if any of the items in res include greedy parts (such as '.*').

interact

t.interact( )

Enters interactive mode, connecting standard input and output to the two ...

Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.