Module 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
|
Telnet
Telnet interface class.
|
|
test()
Test program for telnetlib. |
|
|
|
DEBUGLEVEL = 0
|
|
TELNET_PORT = 23
|
|
IAC = ' \xff '
|
|
DONT = ' \xfe '
|
|
DO = ' \xfd '
|
|
WONT = ' \xfc '
|
|
WILL = ' \xfb '
|
|
theNULL = ' \x00 '
|
|
SE = ' \xf0 '
|
|
NOP = ' \xf1 '
|
|
DM = ' \xf2 '
|
|
BRK = ' \xf3 '
|
|
IP = ' \xf4 '
|
|
AO = ' \xf5 '
|
|
AYT = ' \xf6 '
|
|
EC = ' \xf7 '
|
|
EL = ' \xf8 '
|
|
GA = ' \xf9 '
|
|
SB = ' \xfa '
|
|
BINARY = ' \x00 '
|
|
ECHO = ' \x01 '
|
|
RCP = ' \x02 '
|
|
SGA = ' \x03 '
|
|
NAMS = ' \x04 '
|
|
STATUS = ' \x05 '
|
|
TM = ' \x06 '
|
|
RCTE = ' \x07 '
|
|
NAOL = ' \x08 '
|
|
NAOP = ' \t '
|
|
NAOCRD = ' \n '
|
|
NAOHTS = ' \x0b '
|
|
NAOHTD = ' \x0c '
|
|
NAOFFD = ' \r '
|
|
NAOVTS = ' \x0e '
|
|
NAOVTD = ' \x0f '
|
|
NAOLFD = ' \x10 '
|
|
XASCII = ' \x11 '
|
|
LOGOUT = ' \x12 '
|
|
BM = ' \x13 '
|
|
DET = ' \x14 '
|
|
SUPDUP = ' \x15 '
|
|
SUPDUPOUTPUT = ' \x16 '
|
|
SNDLOC = ' \x17 '
|
|
TTYPE = ' \x18 '
|
|
EOR = ' \x19 '
|
|
TUID = ' \x1a '
|
|
OUTMRK = ' \x1b '
|
|
TTYLOC = ' \x1c '
|
|
VT3270REGIME = ' \x1d '
|
|
X3PAD = ' \x1e '
|
|
NAWS = ' \x1f '
|
|
TSPEED = ' '
|
|
LFLOW = ' ! '
|
|
LINEMODE = ' " '
|
|
XDISPLOC = ' # '
|
|
OLD_ENVIRON = ' $ '
|
|
AUTHENTICATION = ' % '
|
|
ENCRYPT = ' & '
|
|
NEW_ENVIRON = ' \' '
|
|
TN3270E = ' ( '
|
|
XAUTH = ' ) '
|
|
CHARSET = ' * '
|
|
RSP = ' + '
|
|
COM_PORT_OPTION = ' , '
|
|
SUPPRESS_LOCAL_ECHO = ' - '
|
|
TLS = ' . '
|
|
KERMIT = ' / '
|
|
SEND_URL = ' 0 '
|
|
FORWARD_X = ' 1 '
|
|
PRAGMA_LOGON = ' \x8a '
|
|
SSPI_LOGON = ' \x8b '
|
|
PRAGMA_HEARTBEAT = ' \x8c '
|
|
EXOPL = ' \xff '
|
|
NOOPT = ' \x00 '
|
Imports:
sys,
socket,
select
Test program for telnetlib.
Usage: python telnetlib.py [-d] ... [host [port]]
Default host is localhost; default port is 23.
|