节点SSH2连接到路由器

时间:2017-08-03 23:54:34

标签: javascript node.js ssh npm

我正在创建一个应用程序,可以在我的工作中通过SSH连接到路由器,并根据连接到WiFi来接收学生。我有登录信息,可以使用用户名和密码打开一个终端并用SSH连接到它,然后运行命令获取已连接设备的列表。

当我使用带有Node.js的SSH进行设置时,我遇到了一个错误,无法运行任何命令,路由器启动我的连接。我假设它是在我尝试运行命令但无法证明的时候。下面是我的代码和调试日志。任何通过此过滤的帮助都将受到赞赏。

    DEBUG: Local ident: 'SSH-2.0-ssh2js0.1.19'
    DEBUG: Client: Trying 192.168.0.24 on port 22 ...
    DEBUG: Client: Connected
    DEBUG: Parser: IN_INIT
    DEBUG: Parser: IN_GREETING
    DEBUG: Parser: IN_HEADER
    DEBUG: Remote ident: 'SSH-2.0-dropbear_2013.59'
    DEBUG: Outgoing: Writing KEXINIT
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: pktLen:220,padLen:10,remainLen:216
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXINIT
    DEBUG: Comparing KEXINITs ...
    DEBUG: (local) KEX algorithms: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
    DEBUG: (remote) KEX algorithms: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,kexguess2@matt.ucc.asn.au
    DEBUG: KEX algorithm: diffie-hellman-group14-sha1
    DEBUG: (local) Host key formats: ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
    DEBUG: (remote) Host key formats: ssh-rsa
    DEBUG: Host key format: ssh-rsa
    DEBUG: (local) Client->Server ciphers: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour
    DEBUG: (remote) Client->Server ciphers: 3des-ctr,3des-cbc
    DEBUG: Client->Server Cipher: 3des-cbc
    DEBUG: (local) Server->Client ciphers: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour
    DEBUG: (remote) Server->Client ciphers: 3des-ctr,3des-cbc
    DEBUG: Server->Client Cipher: 3des-cbc
    DEBUG: (local) Client->Server HMAC algorithms: hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-sha1-96
    DEBUG: (remote) Client->Server HMAC algorithms: hmac-sha1
    DEBUG: Client->Server HMAC algorithm: hmac-sha1
    DEBUG: (local) Server->Client HMAC algorithms: hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-sha1-96
    DEBUG: (remote) Server->Client HMAC algorithms: hmac-sha1
    DEBUG: Server->Client HMAC algorithm: hmac-sha1
    DEBUG: (local) Client->Server compression algorithms: none,zlib@openssh.com,zlib
    DEBUG: (remote) Client->Server compression algorithms: none
    DEBUG: Client->Server compression algorithm: none
    DEBUG: (local) Server->Client compression algorithms: none,zlib@openssh.com,zlib
    DEBUG: (remote) Server->Client compression algorithms: none
    DEBUG: Server->Client compression algorithm: none
    DEBUG: Outgoing: Writing KEXDH_INIT
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: pktLen:572,padLen:4,remainLen:568
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXDH_REPLY
    DEBUG: Checking host key format
    DEBUG: Checking signature format
    DEBUG: Verifying host fingerprint
    DEBUG: Host accepted by default (no verification)
    DEBUG: Verifying signature
    DEBUG: Outgoing: Writing NEWKEYS
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: pktLen:12,padLen:10,remainLen:8
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: NEWKEYS
    DEBUG: Outgoing: Writing SERVICE_REQUEST (ssh-userauth)
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:28,padLen:10,remainLen:24
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting
    DEBUG: Parser: HMAC size:20
    DEBUG: Parser: IN_PACKETDATAVERIFY
    DEBUG: Parser: Verifying MAC
    DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: SERVICE_ACCEPT
    DEBUG: Outgoing: Writing USERAUTH_REQUEST (none)
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:20,padLen:5,remainLen:16
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting
    DEBUG: Parser: HMAC size:20
    DEBUG: Parser: IN_PACKETDATAVERIFY
    DEBUG: Parser: Verifying MAC
    DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: USERAUTH_FAILURE
    DEBUG: Client: none auth failed
    DEBUG: Outgoing: Writing USERAUTH_REQUEST (password)
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:12,padLen:10,remainLen:8
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting
    DEBUG: Parser: HMAC size:20
    DEBUG: Parser: IN_PACKETDATAVERIFY
    DEBUG: Parser: Verifying MAC
    DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: USERAUTH_SUCCESS
    Client :: ready
    DEBUG: Outgoing: Writing CHANNEL_OPEN (0, session)
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:28,padLen:10,remainLen:24
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting
    DEBUG: Parser: HMAC size:20
    DEBUG: Parser: IN_PACKETDATAVERIFY
    DEBUG: Parser: Verifying MAC
    DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_OPEN_CONFIRMATION
    DEBUG: Outgoing: Writing CHANNEL_REQUEST (0, exec)
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:12,padLen:6,remainLen:8
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting
    DEBUG: Parser: HMAC size:20
    DEBUG: Parser: IN_PACKETDATAVERIFY
    DEBUG: Parser: Verifying MAC
    DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_SUCCESS (0)
    DEBUG: Outgoing: Writing CHANNEL_DATA (0)
    DEBUG: Outgoing: Writing CHANNEL_EOF (0)
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:28,padLen:6,remainLen:24
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting
    DEBUG: Parser: HMAC size:20
    DEBUG: Parser: IN_PACKETDATAVERIFY
    DEBUG: Parser: Verifying MAC
    DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_EXTENDED_DATA (0)
    STDERR: Aborted

    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:12,padLen:6,remainLen:8
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting
    DEBUG: Parser: HMAC size:20
    DEBUG: Parser: IN_PACKETDATAVERIFY
    DEBUG: Parser: Verifying MAC
    DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_EOF (0)
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:36,padLen:10,remainLen:32
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting
    DEBUG: Parser: HMAC size:20
    DEBUG: Parser: IN_PACKETDATAVERIFY
    DEBUG: Parser: Verifying MAC
    DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
    DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_REQUEST (0, exit-status)
    DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
    DEBUG: Parser: IN_PACKET
    DEBUG: Parser: Decrypting
    DEBUG: Parser: pktLen:12,padLen:6,remainLen:8
    DEBUG: Parser: IN_PACKETDATA
    DEBUG: Parser: Decrypting

DEBUG: Parser: HMAC size:20
DEBUG: Parser: IN_PACKETDATAVERIFY
DEBUG: Parser: Verifying MAC
DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
DEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_CLOSE (0)
DEBUG: Outgoing: Writing CHANNEL_CLOSE (0)
DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
Stream :: close

DEBUG: Outgoing: Writing DISCONNECT (BY_APPLICATION)
const express = require('express'),
  Client = require('ssh2').Client;

let MacAdresses = [];
let conn = new Client();

conn.on('ready', () => {
  console.log('Client :: ready');
  conn.exec('show clients', function(err, stream) {
    if (err) throw err;
    stream.on('close', function() {
      console.log('Stream :: close');
      console.log(MacAdresses.toString('utf8'));
      conn.end();
    }).on('data', function(data) {
      console.log('asfasfsaf', data)
      MacAdresses.push(data);
      console.log('STDOUT: ' + data);
    }).stderr.on('data', function(data) {
      console.log('STDERR: ' + data);
    });
    stream.end('ls -l\nexit\n');
  });
}).connect({
  host: '192.168.0.24',
  port: 22,
  username: '******',
  password: '******',
  debug: console.log,
  algorithms: {
    cipher : [
      'aes128-ctr','aes192-ctr','aes256-ctr','arcfour256','arcfour128',
                'aes128-cbc','3des-cbc','blowfish-cbc','cast128-cbc','aes192-cbc',
                'aes256-cbc','arcfour'],
    hmac: ['hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-sha1-96']
}
});

0 个答案:

没有答案