Git Product home page Git Product logo

expect-telnet's Introduction

expect-telnet

telnet automation through expect-send sequences, like in Tcl.

Installation

$ npm install --save expect-telnet

Examples

Log the output of a command

var et = require("expect-telnet");

et("1.2.3.4:23", [
  {expect: "Username", send: "username\r"},
  {expect: "Password", send: "password\r"},
  {expect: "#"       , send: "command\r" },
  {expect: "#"       , out: function(output) {
    console.log(output);
  }, send: "exit\r"}
], function(err) {
  if (err) console.error(err);
});

Start an interactive session

var et = require("expect-telnet");

et("1.2.3.4:23", [
  {expect: "Username", send: "username\r"},
  {expect: "Password", send: "password\r"},
  {expect: "#"       , interact: true    }
], {exit: true}, function(err) {
  if (err) console.error(err);
});

API

expect-telnet(dest, seq, [opts], cb)

  • dest string : Target host and port separated by a colon.
  • seq array : Array of expect steps (objects).
  • opts object : Options object.
  • cb function: Called when an error happens.

Expect step object

  • expect string / regexp : String or RegExp to expect.
  • send string : String to send when expect is found.
  • out function: Output function, receives the output since the previous step.
  • interact boolean : Enter interacive mode with stdin/stdout. There's currently no way out of this mode, so this should be last.

Options

  • timeout *number: Timeout for connection and expect sequences in milliseconds. Set to infinity for no timeout.
  • exit boolean: Whether to exit the process when interacting ends.

© silverwind, distributed under BSD licence

expect-telnet's People

Contributors

silverwind avatar

Stargazers

Earle Ady avatar  avatar Connor Makhlouta avatar  avatar cz avatar  avatar Josh avatar  avatar Sasha Sorokin avatar Takz avatar Ryan Wilcox avatar Chuck Shotton avatar  avatar

Watchers

 avatar James Cloos avatar Takz avatar  avatar

Forkers

imzack

expect-telnet's Issues

Events

Need to add some events for easier output and error handling.

needed to add socket timeout event handler

your package works great to 2 different telnet servers from my ubuntu box running node 4.4.5 (thanks!!)

but on 1 (tripp lite snmpwebcard), the small card apparently gets busy doing other stuff and occasionally hangs the socket in your code without driving any of your sequence timeouts, and since i don't end my code (restarts all day with settimeout), i was getting a buildup of fin_wait2s that wouldn't go away, unless I end my node, which I don't want to do

you already had the socket.setTimeout but no listener, so all I did was add this:
socket.on('timeout', function() {
console.log('socket timeout')
socket.destroy()
})

and no more fin_wait2 buildup on my ubuntu box!!

now if i could just figure out how to clean up a corresponding close_wait on the snmpwebcard... but i can reboot that occasionally so no big deal

i would do a pull request but i really don't know how

thanks again

Is password sent in clear?

My understanding is that this module sends passwords in clear.

As far as I knew, tcl/expect uses some low-layer mechanism at the moment to send passwords and it manages to send them encrypted. But this nodejs module seems to emulate the "expect" syntax only.

Can you please confirm this, or point me to the instructions about shipment of encrypted password?

Thank you for your attention.

Interactive mode behaves strangely

Some characters don't seem to be printed to stdout, I wonder if telnet control characters are interfering, because I have zero handling for them right now.

Error: "port" option should be a number or string: null

Hi,

I am getting the error: "port" option should be a number or string: null. The hostname is: GPO_HBRISAS_DSL01:23

et("GPO_HBRISAS_DSL01:23", seq, {timeout: 60000, exit: true }, function(err) {
  if (err) { // If error
    console.log(err);
    callback(err.toString()); // Returns error
  }
});

If I change the hostname to an IP address works fine :

et("192.0.2.25:23", seq, {timeout: 60000, exit: true }, function(err) {
  if (err) { // If error
    console.log(err);
    callback(err.toString()); // Returns error
  }
});

Regards,
Oscar.

SSH support

Maybe a module rename is in order with this :)

Option to print somenting to output after or before a send

Hi, I'm doing some tests with your library and it's working really fine. But I found myself in a situation where I need to execute several commands on a remote machine and it would be nice for parsing purpose to be able to send some kind of string between send calls something like this:

et("127.0.0.1:23", expect = [
    {expect: "Login:"    , send: `mylogin\n`},
    {expect: "Password:", send: `${senha}\n`},
    {expect: ">", send: "first command\n", delimiter: '-'.repeate(80)+"\n" },
    {expect: ">"    , send: "second command\n"},
    {expect: ">"    , out: function(result){
        console.log(result)
    }, send: 'exit\n'},
], function(err) {
        if (err)  console.error(err)
});

If the target machine is an linux or have some sort of echo or print command is ok, but in my case it's a proprietary device which doesn't have any means to print some string to the output, so it would be nice to be able to send this delimiter between commands in order to make ease to parse the output e use the same connection for multiples commands, or could be an event after or before the expect so we would be able to take custom actions in the middle of the processing.

Thanks

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.