telnetlib

TELNET client class.

Based on RFC 854: TELNET Protocol Specification, by J. Postel and J. Reynolds

Example:

>>> from telnetlib import Telnet
>>> tn = Telnet('www.python.org', 79)   # connect to finger port
>>> tn.write('guido\r\n')
>>> print tn.read_all()
Login       Name               TTY         Idle    When    Where
guido    Guido van Rossum      pts/2        <Dec  2 11:10> snag.cnri.reston..
>>>

Note that read_all() won’t read until eof – it just reads some data – but it guarantees to read at least one byte unless EOF is hit.

It is possible to pass a Telnet object to select.select() in order to wait until more data is available. Note that in this case, read_eager() may return ‘’ even if there was data on the socket, because the protocol negotiation may have eaten the data. This is why EOFError is needed in some cases to distinguish between “no data” and “connection closed” (since the socket also appears ready for reading when it is closed).

To do: - option negotiation - timeout should be intrinsic to the connection object instead of an

option on one of the read calls only

Functions

test() Test program for telnetlib.

Classes

Telnet([host, port, timeout]) Telnet interface class.