mkozjak / node-telnet-client

A simple telnet client for Node.js
Other
348 stars 97 forks source link

I'm trying to connect telnet remote server,when i run this code it not shows nothing #166

Closed Kaimunchi closed 4 years ago

Kaimunchi commented 4 years ago
'use strict'

const Promise = require('bluebird')
const Telnet = require('telnet-client')

async function run() {
  let connection = new Telnet()
  let params = {
    host: '1.2.3.4',
    port: 6023,
    shellPrompt: '/ # ',
    debug: true,
    username: 'admin',
    password: 'admin', // or negotiationMandatory: false
    timeout: 1500
  }

  try {
    await connection.connect(params)
  } catch (error) {
    // handle the throw (timeout)
  }
  try {
  let res = await connection.exec(cmd)
  console.log('async result:', res)
  }
  catch (error) {
    // handle the throw (timeout)
  }

}

run()
mkozjak commented 4 years ago

I suppose you're connecting to busybox based on your shell prompt?

Kaimunchi commented 4 years ago

here i want to connect remote telnet server.

mkozjak commented 4 years ago

Use appropriate shell prompt. The one you get when manually connecting via linux/windows.

Kaimunchi commented 4 years ago

i'm using windows terminal

mkozjak commented 4 years ago

@Kaimunchi - This is not a paid service. You leverage this library to make it work for you. People don't just help everyone here for free. I invested at least two years of my precious time to provide you with this library for free, so the least you can do is try looking into what might be the issue on your side and also provide bugfixes if they arise. Thank you.

Kaimunchi commented 4 years ago

My apologies

Kaimunchi commented 4 years ago

I'm trying to connect mikrotik router using this code,its giving this error,but in router telnet logs shows its connected via telnet


connect
connection closed
Unhandled rejection Error: Cannot connect
    at Socket.<anonymous> (D:\New folder\node_modules\telnet-client\lib\index.js:85:25)
    at Object.onceWrapper (events.js:416:28)
    at Socket.emit (events.js:310:20)
    at Socket._onTimeout (net.js:479:8)
    at listOnTimeout (internal/timers.js:549:17)      
    at processTimers (internal/timers.js:492:7)       

Unhandled rejection Error: Socket closes
    at Socket.<anonymous> (D:\New folder\node_modules\telnet-client\lib\index.js:121:18)
    at Socket.emit (events.js:310:20)
    at TCP.<anonymous> (net.js:672:12)

connection closed ```
#this is the code what i'm trying 
```var telnet = require('telnet-client');
var connection = new telnet();

var params = {
  host: '1.2.3.4',
  port: 6023,
  shellPrompt: /[>\]]/,
  loginPrompt: "Login: ",
  passwordPrompt: "Password: ",
  username: 'admin',
  password: 'admin',
  timeout: 10000,
}
connection.on('connect',function()
{
console.log('connect');
});
connection.connect('ready',function()
{
    connection.exec("interface enable numbers=0");
});
connection.on('timeout', function() {
      console.log('socket timeout!')
      connection.end();
    });
    connection.on('close', function() {
  console.log('connection closed');
});
connection.connect(params); ```