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’

connection_made(transport)[source]

Callback for connection made to server.

send_ttype()[source]

Callback for responding to TTYPE requests.

send_tspeed()[source]

Callback for responding to TSPEED requests.

send_xdisploc()[source]

Callback for responding to XDISPLOC requests.

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

dict

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.

Parameters

offered (list) – list of CHARSET options offered by server.

Returns

character encoding agreed to be used.

Return type

Union[str, None]

send_naws()[source]

Callback for responding to NAWS requests.

Return type

(int, int)

Returns

client window size as (rows, columns).

encoding(outgoing=None, incoming=None)[source]

Return encoding for the given stream direction.

Parameters
  • outgoing (bool) – Whether the return value is suitable for encoding bytes for transmission to server.

  • incoming (bool) – Whether the return value is suitable for decoding bytes received by the client.

Raises

TypeError – when a direction argument, either outgoing or incoming, was not set True.

Returns

'US-ASCII' for the directions indicated, unless BINARY RFC 856 has been negotiated for the direction indicated or :attr`force_binary` is set True.

Return type

str

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.

send_naws()[source]

Callback replies to request for window size, NAWS RFC 1073.

Return type

(int, int)

Returns

window dimensions by lines and columns

send_env(keys)[source]

Callback replies to request for env values, NEW_ENVIRON RFC 1572.

Return type

dict

Returns

super class value updated with window LINES and COLUMNS.

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
  • host (str) – Remote Internet TCP Server host.

  • port (int) – Remote Internet host TCP port.

  • 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'.

  • encoding (str) –

    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 value LANG, and by CHARSET RFC 2066 negotiation.

    The server’s attached reader, writer streams 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 (Callable) – A asyncio.coroutine() that is called after negotiation completes, receiving arguments (reader, writer). The reader is a TelnetReader instance, the writer is a TelnetWriter instance.

  • 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 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 failing BINARY negotiation, RFC 856. This parameter has no effect when encoding=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.

  • limit (int) – The buffer limit for reader stream.

Return (reader, writer)

The reader is a TelnetReader instance, the writer is a TelnetWriter instance.

This function is a coroutine().