client
Telnet Client API for the ‘telnetlib3’ python package.
- class TelnetClient(term='unknown', cols=80, rows=25, tspeed=(38400, 38400), xdisploc='', send_environ=None, shell=None, encoding='utf8', encoding_errors='strict', force_binary=False, connect_minwait=0, connect_maxwait=4.0, compression=None, limit=None, waiter_closed=None, _waiter_connected=None, gmcp_modules=None)[source]
Telnet client that supports all common options.
Useful for automation, appearing as a virtual terminal to the remote end without requiring an interactive terminal to run.
Initialize TelnetClient with terminal parameters.
- 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’
- DEFAULT_SEND_ENVIRON = ('TERM', 'LANG', 'COLUMNS', 'LINES', 'COLORTERM')
Default environment variables to send via NEW_ENVIRON
- connection_made(transport)[source]
Handle connection made to server.
Wire up telnet option callbacks for terminal type, speed, display, environment, window size, and character set negotiation.
- Return type:
- on_gmcp(package, data)[source]
Store incoming GMCP data on
writer.ctx, merging dict updates.- Return type:
- send_env(keys)[source]
Callback for responding to NEW_ENVIRON requests.
Only sends variables listed in
_send_environ(set viasend_environparameter or--send-environCLI option).- Parameters:
keys (
Sequence[str]) – Values are requested for the keys specified. When empty, all environment values that wish to be volunteered should be returned.- Return type:
- Returns:
Environment values requested, or an empty string for keys not available. A return value must be given for each key requested.
- send_charset(offered)[source]
Callback for responding to CHARSET requests.
Simplified policy:
If client has explicit encoding that matches an offered charset, use it
If client has explicit encoding that isn’t offered,
For Latin-1 (weak default), accept first viable offered encoding
For other explicit encodings, reject (keep client’s choice)
If no explicit encoding preference, accept first viable offered encoding
If no viable encodings found, reject
- on_request_charset()[source]
Offer callback for client-initiated CHARSET REQUEST, RFC 2066.
Called by
request_charset()to determine which character sets the client offers to the server.
- on_request_environ()[source]
Offer callback for client-initiated NEW_ENVIRON SEND, RFC 1572.
Called by
request_environ()to determine which environment variable names the client requests from the server.
- 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='', send_environ=None, shell=None, encoding='utf8', encoding_errors='strict', force_binary=False, connect_minwait=0, connect_maxwait=4.0, compression=None, limit=None, waiter_closed=None, _waiter_connected=None, gmcp_modules=None)[source]
Telnet client for sessions with a network virtual terminal (NVT).
Initialize TelnetClient with terminal parameters.
- async open_connection(host=None, port=23, *, client_factory=None, family=0, flags=0, local_addr=None, encoding='utf8', encoding_errors='replace', force_binary=False, term='unknown', cols=80, rows=25, tspeed=(38400, 38400), xdisploc='', shell=None, connect_minwait=0, connect_maxwait=3.0, connect_timeout=None, compression=None, waiter_closed=None, _waiter_connected=None, limit=None, send_environ=None, ssl=None, server_hostname=None)[source]
Connect to a TCP Telnet server as a Telnet client.
- Parameters:
port (
int) – Remote Internet host TCP port.client_factory (
Optional[Callable[...,BaseClient]]) – Client connection class factory. WhenNone,TelnetTerminalClientis used when stdin is attached to a terminal,TelnetClientotherwise.family (
int) – Same meaning asasyncio.loop.create_connection().flags (
int) – Same meaning asasyncio.loop.create_connection().local_addr (
Optional[Tuple[str,int]]) – Same meaning asasyncio.loop.create_connection().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 valueLANG, and by CHARSET RFC 2066 negotiation.The server’s attached
reader, writerstreams accept and return unicode, unless this value is explicitly setFalse. In that case, the attached streams interfaces are bytes-only.encoding_errors (
str) – Same meaning ascodecs.Codec.encode().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[int,int]) – 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).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 compliant, 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.connect_timeout (
Optional[float]) – Timeout in seconds for the TCP connection to be established. WhenNone(default), no timeout is applied and the connection attempt may block indefinitely. When specified, aConnectionErroris raised if the connection is not established within the given time.compression (
Optional[bool]) – MCCP compression policy.None(default) passively accepts compression when offered by the server.Trueactively requests MCCP2/MCCP3.Falserejects all compression offers.force_binary (
bool) – WhenTrue, the encoding is used regardless of BINARY mode negotiation.waiter_closed (
Optional[Future[None]]) – Future that completes when the connection is closed.shell (
Optional[Callable[[Union[TelnetReader,TelnetReaderUnicode],Union[TelnetWriter,TelnetWriterUnicode]],Coroutine[Any,Any,None]]]) – An async function that is called after negotiation completes, receiving arguments(reader, writer).ssl (
Union[bool,SSLContext,None]) – TLS configuration.Truecreates a defaultssl.create_default_context()that verifies CA certificates. Anssl.SSLContextgives full control.None(default) uses plain TCP.server_hostname (
Optional[str]) – Hostname for TLS certificate verification. Whensslis truthy and server_hostname isNone, defaults to host.
- Return type:
Tuple[Union[TelnetReader,TelnetReaderUnicode],Union[TelnetWriter,TelnetWriterUnicode]]- Returns:
The reader is a
TelnetReaderinstance, the writer is aTelnetWriterinstance.