{"id":18234652,"url":"https://github.com/paddor/em-simple_telnet","last_synced_at":"2025-04-04T02:33:12.908Z","repository":{"id":1890336,"uuid":"2816367","full_name":"paddor/em-simple_telnet","owner":"paddor","description":"Simple telnet client functionality on EventMachine","archived":false,"fork":false,"pushed_at":"2016-01-17T03:36:05.000Z","size":53,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-31T13:29:07.984Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paddor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-20T23:27:27.000Z","updated_at":"2024-04-30T13:38:53.000Z","dependencies_parsed_at":"2022-09-09T01:00:08.684Z","dependency_job_id":null,"html_url":"https://github.com/paddor/em-simple_telnet","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddor%2Fem-simple_telnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddor%2Fem-simple_telnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddor%2Fem-simple_telnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paddor%2Fem-simple_telnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paddor","download_url":"https://codeload.github.com/paddor/em-simple_telnet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223084641,"owners_count":17084910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-04T23:05:03.078Z","updated_at":"2024-11-04T23:05:04.640Z","avatar_url":"https://github.com/paddor.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status on Travis CI](https://travis-ci.org/paddor/em-simple_telnet.svg?branch=master)](https://travis-ci.org/paddor/em-simple_telnet?branch=master)\n[![Inline docs](http://inch-ci.org/github/paddor/em-simple_telnet.svg?branch=master\u0026style=shields)](http://inch-ci.org/github/paddor/em-simple_telnet)\n\n# SimpleTelnet\n\nProvides telnet client functionality.\n\nThis class was once derived from the\n[Net::Telnet](http://ruby-doc.org/stdlib-2.0.0/libdoc/net/telnet/rdoc/Net/Telnet.html)\nclass in Ruby's standard library.  It uses EventMachine, adds some\nfunctionality around logging and other useful features that came up useful back\nwhen I was using this code productively.\n\nIt was developed with simplicity in mind. It tries to hide the complexity of\nasynchronous programming using Fibers.\n\n\nHere's the [API documentation](http://www.rubydoc.info/gems/em-simple_telnet)\nof the current release.\n\n## News\n\nWith the coming up release I plan to modernize this repository a bit. That\nmeans porting it to a standard `bundle gem`-like structure, and improve\ndocumentation and make it more YARD compatible, which is used on\n[rubydoc.info](http://www.rubydoc.info/github/paddor/em-simple_telnet/master).\n\nI plan to add specs as soon as I've released a related gem called\n_em-telnet_server_ (see below).\n\n## Overview\n\nThis section has been copied and slightly modified from Net::Telnet's documentation.\n\nThe telnet protocol allows a client to login remotely to a user account on a\nserver and execute commands via a shell.  The equivalent is done by creating a\nSimpleTelnet::Connection instance with the `:host` option set to your host\nalong with a block which defines the task to be done on the host. The\nestablished connection (login already performed by `#login`) is passed to the\nblock. In the block, you'd normally make one or more calls to `#cmd`. After the\nblock returns, the connection is automatically closed.\n\nThis class can also be used to connect to non-telnet services, such as SMTP\nor HTTP.  In this case, you normally want to provide the `:port`\noption to specify the port to connect to, and set the `:telnet_mode`\noption to `false` to prevent the client from attempting to interpret telnet\ncommand sequences.  Generally, `#login` will not work with other protocols,\nand you have to handle authentication yourself.\n\n## Differences to Net::Telnet\n\n* based on EventMachine and `Fiber`s\n* uses lowercase Symbols (like `:host`) for options (instead of `\"Host\")\n* provides per connection logging for:\n  * general activity (see `#logger`)\n  * output log (see the option `:output_log`, `#output_logger`, and `#output_log`)\n  * commands sent (see the option `:command_log`, `#command_logger`, and `#command_log`)\n  * debug logging (if `logger.debug?`)\n    * prints recently received data in a more human-friendly 0.5s interval, as\n      opposed to single characters (because EventMachine is fast)\n* no hexdump log\n* can handle extremely big outputs by deferring checking for the prompt in the\n  output in case it's getting huge\n* the `:connect_timeout` which specifies the timeout for establishing new\n  connections\n* the `:wait_time` option which is useful for commands that result in multiple\n  prompts\n  - it specifies the time to wait for more data to arrive after what looks like\n    a prompt\n* `#last_command` sent\n* `#last_prompt` last prompt matched\n* `#logged_in` time when login succeeded\n* `#last_data_sent_at` time when last data was sent\n* `SimpleTelnet::TimeoutError` exceptions know the causing command and on which\n  host it happened (`#hostname`, `#command`)\n\n## Examples\n\nIf you're starting from scratch and simply want to access a single host via\ntelnet, do something like this:\n\n```ruby\nopts = {\n  host: \"localhost\",\n  username: \"user\",\n  password: \"secret\",\n}\n\nEM::P::SimpleTelnet.new(opts) do |host|\n  # At this point, we're already logged in.\n\n  host.cmd(\"touch /my/file\")\n\n  # get some output\n  puts host.cmd(\"ls -la\")\n\n  host.timeout(30) do\n    # custom timeout for this block\n    host.cmd \"slow command\"\n  end\nend\n```\n\nIf you already have an EventMachine reactor running, you can use SimpleTelnet\ninside it, like here:\n\n```ruby\nEventMachine.run do\n\n  opts = {\n    host: \"localhost\",\n    username: \"user\",\n    password: \"secret\",\n    output_log: \"output.log\", # log output to file\n    command_log: \"command.log\", # log commands to file\n  }\n\n  EM::P::SimpleTelnet.new(opts) do |host|\n    # already logged in\n    puts host.cmd(\"ls -la\")\n  end\nend\n```\n\nBy the way, `SimpleTelnet::Connection` and\n`EventMachine::Protocols::SimpleTelnet` are the same.\n\n# Related Projects\n\nI'm planning to release\n[_em-massive_telnet_](https://github.com/paddor/em-massive_telnet) for\nmassively parallel telnet connections (from client to server) and\n[_em-telnet_server_](https://github.com/paddor/em-telnet_server) which can be\nused to build your own telnet server based on EventMachine.\n\nI've written the code for these two gems years ago, but I'll need to carefully\nextract it so any sensitive information is stripped off.\n\n## References\n\nThere is a large number of RFCs relevant to the Telnet protocol.\nRFCs 854-861 define the base protocol.  For a complete listing\nof relevant RFCs, see\nhttp://www.omnifarious.org/~hopper/technical/telnet-rfc.html\n\n## License\n\nThe gem is available as open source under the terms of the [ISC License](http://opensource.org/licenses/ISC).\nSee the [LICENSE](https://github.com/paddor/em-simple_telnet/blob/master/LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaddor%2Fem-simple_telnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaddor%2Fem-simple_telnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaddor%2Fem-simple_telnet/lists"}