Telnet Client API for the ‘telnetlib3’ python package.
TelnetClient(term='unknown', cols=80, rows=25, tspeed=(38400, 38400), xdisploc='', *args, **kwargs)¶
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.
Begin on-connect negotiation.
A Telnet client is expected to send only a minimal amount of client session options immediately after connection, it is generally the server which dictates server option support.
Deriving implementations should always call
Callback, return whether negotiation is complete.
Parameters: final¶ (bool) – Whether this is the final time this callback will be requested to answer regarding protocol negotiation. Returns: Whether negotiation is over (client end is satisfied). Return type: bool
Method is called on each new command byte processed until negotiation is considered final, or after
connect_maxwaithas elapsed, setting
This method returns False until
connect_minwaithas elapsed, ensuring the server may batch telnet negotiation demands without prematurely entering the callback shell.
super().check_negotiation()is called and conditionally combined when derived.
Called when the connection is lost or closed.
Parameters: exc¶ (Exception) – exception.
Noneindicates a closing EOF sent by this end.
Callback for connection made to server.
Process bytes received by transport.
Time elapsed since client connected, in seconds as float.
Return encoding for the given stream direction.
TypeError – when a direction argument, either
incoming, was not set
'US-ASCII'for the directions indicated, unless
BINARYRFC 856 has been negotiated for the direction indicated or :attr`force_binary` is set
Value resolution order (first-matching):
- value set by
- value of
get_extra_info()using key argument,
- value of
US-ASCIIwhen binary transmission not allowed.
- value set by
Called when the other end calls write_eof() or equivalent.
Get optional client protocol or transport information.
Time elapsed since data last received, in seconds as float.
Callback for responding to CHARSET requests.
Receives a list of character encodings offered by the server 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
self.encodingif matched in the offered list.
Parameters: offered¶ (list) – list of CHARSET options offered by server. Returns: character encoding agreed to be used. Return type: str or None.
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: dict[(key, value), .]
Callback for responding to NAWS requests.
Return type: (int, int) Returns: client window size as (rows, columns).
Callback for responding to TSPEED requests.
Callback for responding to TTYPE requests.
Callback for responding to XDISPLOC requests.
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)¶
Connect to a TCP Telnet server as a Telnet client.
- host¶ (str) – Remote Internet TCP Server host.
- port¶ (int) – Remote Internet host TCP port.
- client_factory¶ (client_base.BaseClient) – Client connection class
TelnetTerminalClientis used when stdin is attached to a terminal,
- loop¶ (asyncio.base_events.BaseEventLoop) – set the event loop to use.
The return value of
asyncio.get_event_loop()is used when unset.
- family¶ (int) – Same meaning as
- flags¶ (int) – Same meaning as
- local_addr¶ (tuple) – Same meaning as
- log¶ (logging.Logger) – target logger, if None is given, one is created
using the namespace
- encoding¶ (str) –
The default assumed encoding, or
Falseto 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 value
LANG, and by CHARSET RFC 2066 negotiation.
The server’s attached
reader, writerstreams accept and return unicode, unless this value explicitly set
False. 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¶ (asyncio.coroutine) – A coroutine that is called after
negotiation completes, receiving arguments
(reader, writer). The reader is a
TelnetStreamReaderinstance, the writer is a
- connect_minwait¶ (float) –
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
shellfor 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
- force_binary¶ (bool) – When
True, the encoding specified is used for both directions even when failing
BINARYnegotiation, RFC 856. This parameter has no effect when
- encoding_errors¶ (str) – Same meaning as
- 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.
- limit¶ (int) – The buffer limit for reader stream.
Return (reader, writer):
The reader is a
TelnetStreamReaderinstance, the writer is a
This function is a