Giter Club home page Giter Club logo

telnetlib3's Introduction

Travis Continuous Integration Coveralls Code Coverage Latest Version Downloads

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('\r\nWould 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):
    while True:
        # read stream until '?' mark is found
        outp = yield from reader.read(1024)
        if not outp:
            # End of File
            break
        elif '?' in outp:
            # reply all questions with 'y'.
            writer.write('y')

        # display all server output
        print(outp, flush=True)

    # EOF
    print()

loop = asyncio.get_event_loop()
coro = telnetlib3.open_connection('localhost', 6023, shell=shell)
reader, writer = loop.run_until_complete(coro)
loop.run_until_complete(writer.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 nethack.alt.org
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, for example:

tel:sh> help
quit, writer, slc, toggle [option|all], reader, proto

tel:sh> writer
<TelnetWriter server mode:kludge +lineflow -xon_any +slc_sim server-will:BINARY,ECHO,SGA client-will:BINARY,NAWS,NEW_ENVIRON,TTYPE>

tel:sh> reader
<TelnetReaderUnicode encoding='utf8' limit=65536 buflen=0 eof=False>

tel:sh> toggle all
wont echo.
wont suppress go-ahead.
wont outbinary.
dont inbinary.
xon-any enabled.
lineflow disabled.

tel:sh> reader
<TelnetReaderUnicode encoding='US-ASCII' limit=65536 buflen=1 eof=False>

tel:sh> writer
<TelnetWriter server mode:local -lineflow +xon_any +slc_sim client-will:NAWS,NEW_ENVIRON,TTYPE>

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

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/

telnetlib3's People

Contributors

aidanpb avatar andrewnelis avatar fried avatar gtaylor avatar hughpyle avatar jquast avatar sethb0 avatar tarkatronic avatar tehmaze avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.