client¶
Telnet Client API for the ‘telnetlib3’ python package.
-
class
TelnetClient
(term='unknown', cols=80, rows=25, tspeed=38400, 38400, xdisploc='', *args, **kwargs)[source]¶ Telnet client that supports all common options.
This class is useful for automation, it appears to be a virtual terminal to the remote end, but does not require an interactive terminal to run.
Class initializer.
-
DEFAULT_LOCALE
= 'en_US'¶ On
send_env()
, the value of ‘LANG’ will be ‘C’ for binary transmission. When encoding is specified (utf8 by default), the LANG variable must also contain a locale, this value is used, providing a full default LANG value of ‘en_US.utf8’
-
send_env
(keys)[source]¶ Callback for responding to NEW_ENVIRON requests.
- Parameters
keys¶ (dict) – Values are requested for the keys specified. When empty, all environment values that wish to be volunteered should be returned.
- Returns
dictionary of environment values requested, or an empty string for keys not available. A return value must be given for each key requested.
- Return type
-
send_charset
(offered)[source]¶ Callback for responding to CHARSET requests.
Receives a list of character encodings offered by the server as
offered
such as('LATIN-1', 'UTF-8')
, for which the client may return a value agreed to use, or None to disagree to any available offers. Server offerings may be encodings or codepages.The default implementation selects any matching encoding that python is capable of using, preferring any that matches
encoding
if matched in the offered list.
-
encoding
(outgoing=None, incoming=None)[source]¶ Return encoding for the given stream direction.
-
-
class
TelnetTerminalClient
(term='unknown', cols=80, rows=25, tspeed=38400, 38400, xdisploc='', *args, **kwargs)[source]¶ Telnet client for sessions with a network virtual terminal (NVT).
Class initializer.
-
open_connection
(host=None, port=23, *, client_factory=None, loop=None, family=0, flags=0, local_addr=None, log=None, encoding='utf8', encoding_errors='replace', force_binary=False, term='unknown', cols=80, rows=25, tspeed=38400, 38400, xdisploc='', shell=None, connect_minwait=2.0, connect_maxwait=3.0, waiter_closed=None, _waiter_connected=None, limit=None)[source]¶ Connect to a TCP Telnet server as a Telnet client.
- Parameters
client_factory¶ (client_base.BaseClient) – Client connection class factory. When
None
,TelnetTerminalClient
is used when stdin is attached to a terminal,TelnetClient
otherwise.loop¶ (asyncio.AbstractEventLoop) – set the event loop to use. The return value of
asyncio.get_event_loop()
is used when unset.family¶ (int) – Same meaning as
asyncio.loop.create_connection()
.flags¶ (int) – Same meaning as
asyncio.loop.create_connection()
.local_addr¶ (tuple) – Same meaning as
asyncio.loop.create_connection()
.log¶ (logging.Logger) – target logger, if None is given, one is created using the namespace
'telnetlib3.server'
.The default assumed encoding, or
False
to disable unicode support. This value is used for decoding bytes received by and encoding bytes transmitted to the Server. These values are preferred in response to NEW_ENVIRON RFC 1572 as environment valueLANG
, and by CHARSET RFC 2066 negotiation.The server’s attached
reader, writer
streams accept and return unicode, unless this value explicitly setFalse
. In that case, the attached streams interfaces are bytes-only.term¶ (str) – Terminal type sent for requests of TTYPE, RFC 930 or as Environment value TERM by NEW_ENVIRON negotiation, RFC 1672.
cols¶ (int) – Client window dimension sent as Environment value COLUMNS by NEW_ENVIRON negotiation, RFC 1672 or NAWS RFC 1073.
rows¶ (int) – Client window dimension sent as Environment value LINES by NEW_ENVIRON negotiation, RFC 1672 or NAWS RFC 1073.
tspeed¶ (tuple) – Tuple of client BPS line speed in form
(rx, tx
) for receive and transmit, respectively. Sent when requested by TSPEED, RFC 1079.xdisploc¶ (str) – String transmitted in response for request of XDISPLOC, RFC 1086 by server (X11).
shell¶ (Callable) – A
asyncio.coroutine()
that is called after negotiation completes, receiving arguments(reader, writer)
. The reader is aTelnetReader
instance, the writer is aTelnetWriter
instance.The client allows any additional telnet negotiations to be demanded by the server within this period of time before launching the shell. Servers should assert desired negotiation on-connect and in response to 1 or 2 round trips.
A server that does not make any telnet demands, such as a TCP server that is not a telnet server will delay the execution of
shell
for exactly this amount of time.connect_maxwait¶ (float) – If the remote end is not complaint, or otherwise confused by our demands and failing to reply to pending negotiations, the shell continues anyway after the greater of this value or
connect_minwait
elapsed.force_binary¶ (bool) – When
True
, the encoding specified is used for both directions even when failingBINARY
negotiation, RFC 856. This parameter has no effect whenencoding=False
.encoding_errors¶ (str) – Same meaning as
codecs.Codec.encode()
.connect_minwait¶ – XXX
connect_maxwait¶ – If the remote end is not complaint, or otherwise confused by our demands, the shell continues anyway after the greater of this value has elapsed. A client that is not answering option negotiation will delay the start of the shell by this amount.
- Return (reader, writer)
The reader is a
TelnetReader
instance, the writer is aTelnetWriter
instance.
This function is a
coroutine()
.