Skip to main content

Python 3 asyncio Telnet server and client Protocol library

Project description

Travis Continuous Integration Coveralls Code Coverage Latest Version Downloads Join Chat

Introduction

telnetlib3 is a Telnet Client and Server library for python. This project requires python 3.3 and later, using the asyncio module.

Quick Example

Authoring a Telnet Server using Streams interface that offers a basic war game:

import asyncio, telnetlib3

@asyncio.coroutine
def shell(reader, writer):
    writer.write('Would you like to play a game? ')
    inp = yield from reader.read(1)
    if inp:
        writer.echo(inp)
        writer.write('\r\nThey say the only way to win '
                     'is to not play at all.\r\n')
        yield from writer.drain()
    writer.close()

loop = asyncio.get_event_loop()
coro = telnetlib3.create_server(port=6023, shell=shell)
server = loop.run_until_complete(coro)
loop.run_until_complete(server.wait_closed())

Authoring a Telnet Client that plays the war game with this server:

import asyncio, telnetlib3

@asyncio.coroutine
def shell(reader, writer):
    buf = ''
    while True:
        outp = yield from reader.read(1024)
        if not outp:
            # EOF
            return

        print(outp, end='', flush=True)

        if '?' in outp:
            # reply all questions with 'y'.
            writer.write('y')

    print()

loop = asyncio.get_event_loop()
coro = telnetlib3.open_connection('localhost', 6023, shell=shell)
reader, _ = loop.run_until_complete(coro)
loop.run_until_complete(reader.protocol.waiter_closed)

Command-line

Two command-line scripts are distributed with this package.

telnetlib3-client

Small terminal telnet client. Some example destinations and options:

telnetlib3-client rainmaker.wunderground.com
telnetlib3-client --encoding=cp437 --force-binary blackflag.acid.org
telnetlib3-client htc.zapto.org

telnetlib3-server

Telnet server providing the default debugging shell. This provides a simple shell server that allows introspection of the session’s values.

Both command-line scripts accept argument --shell=my_module.fn_shell describing a python module path to a coroutine of signature shell(reader, writer).

Features

The following RFC specifications are implemented:

  • rfc-727, “Telnet Logout Option,” Apr 1977.

  • rfc-779, “Telnet Send-Location Option”, Apr 1981.

  • rfc-854, “Telnet Protocol Specification”, May 1983.

  • rfc-855, “Telnet Option Specifications”, May 1983.

  • rfc-856, “Telnet Binary Transmission”, May 1983.

  • rfc-857, “Telnet Echo Option”, May 1983.

  • rfc-858, “Telnet Suppress Go Ahead Option”, May 1983.

  • rfc-859, “Telnet Status Option”, May 1983.

  • rfc-860, “Telnet Timing mark Option”, May 1983.

  • rfc-885, “Telnet End of Record Option”, Dec 1983.

  • rfc-1073, “Telnet Window Size Option”, Oct 1988.

  • rfc-1079, “Telnet Terminal Speed Option”, Dec 1988.

  • rfc-1091, “Telnet Terminal-Type Option”, Feb 1989.

  • rfc-1096, “Telnet X Display Location Option”, Mar 1989.

  • rfc-1123, “Requirements for Internet Hosts”, Oct 1989.

  • rfc-1184, “Telnet Linemode Option (extended options)”, Oct 1990.

  • rfc-1372, “Telnet Remote Flow Control Option”, Oct 1992.

  • rfc-1408, “Telnet Environment Option”, Jan 1993.

  • rfc-1571, “Telnet Environment Option Interoperability Issues”, Jan 1994.

  • rfc-1572, “Telnet Environment Option”, Jan 1994.

  • rfc-2066, “Telnet Charset Option”, Jan 1997.

Further Reading

Further documentation available at https://telnetlib3.readthedocs.org/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

telnetlib3-1.0.0.tar.gz (64.3 kB view details)

Uploaded Source

Built Distribution

telnetlib3-1.0.0-py3-none-any.whl (88.7 kB view details)

Uploaded Python 3

File details

Details for the file telnetlib3-1.0.0.tar.gz.

File metadata

  • Download URL: telnetlib3-1.0.0.tar.gz
  • Upload date:
  • Size: 64.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for telnetlib3-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0b056d3b8bc593dd198e69a0e2f2905a85166aab3508b3ac80b910b7c2584f5d
MD5 6bdc2eebd19c2b9509c3de1dbdb3539a
BLAKE2b-256 e041ead26e2b21606345d04e64f0bb307c325c93c1e9a2a37d3318048b3127a2

See more details on using hashes here.

File details

Details for the file telnetlib3-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for telnetlib3-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22d1dfddef34b5654a682c338537a02d77fb421160f1cd1622e7c23b5fef1ec2
MD5 40f035388101de85f90fa186d191044e
BLAKE2b-256 22dca51cc026c09c4df4241849c2f792d6b6159591dee6f3a6bbe8ef769a2ca1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page