1

I am not a expert on node usually i would try to troubleshoot and hack the thing till it works but i am short on time and need some advice

using the NPM-ssh2 package i want to be able to execute a command on my customer router

i just need to know the easiest way to do this as the npm docs are not giving me much joy this is what i have so far and it works connects no problem now i need to know how to exec the commands on the remote system


    var Client = require('ssh2').Client
const password = 'squerespace1001';

var office = new Client();

office.connect({
    host: '192.168.1.1',
    username: 'admin',
    port: 22,
    password: password
  });
Reyn Wouda
  • 13
  • 3

1 Answers1

0

I did solve i issue and it works great not sure its the best way but should any one struggle feel free to use this code

 var Client = require('ssh2').Client;

var office = new Client();
office.on('ready', function() {
  console.log('Client :: ready');
  office.exec('ip address print', function(err, stream) {
    if (err) console.log(err);
    stream.on('close', function(code, signal) {
      console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
      office.end();
    }).on('data', function(data) {
      console.log('STDOUT: ' + data);
    })
  });
}).connect({
  host: '192.168.1.1',
  port: 22,
  username: 'admin',
  password: 'admin'
});
Reyn Wouda
  • 13
  • 3