All Projects → mkozjak → Node Telnet Client

mkozjak / Node Telnet Client

Licence: other
A simple telnet client for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Telnet Client

dystopia
Low to medium multithreaded Ubuntu Core honeypot coded in Python.
Stars: ✭ 59 (-78.93%)
Mutual labels:  socket, telnet
micrOS
micrOS - mini automation OS for DIY projects requires reliable direct communication
Stars: ✭ 55 (-80.36%)
Mutual labels:  socket, telnet
node-abstractsocket
Abstract namespace socket support for Node
Stars: ✭ 24 (-91.43%)
Mutual labels:  socket
Stick
solution of "sticking packets" for TCP network transmission
Stars: ✭ 261 (-6.79%)
Mutual labels:  socket
BlueSSLService
SSL/TLS Add-in for BlueSocket using Secure Transport and OpenSSL
Stars: ✭ 87 (-68.93%)
Mutual labels:  socket
RxSocket
RxSocket连接
Stars: ✭ 31 (-88.93%)
Mutual labels:  socket
alveare
🐝 Multi-client, multi-threaded reverse shell handler written in Node.js
Stars: ✭ 68 (-75.71%)
Mutual labels:  socket
as2-server
A standalone Java AS2 server - see as2-lib for the generic parts
Stars: ✭ 29 (-89.64%)
Mutual labels:  socket
Vorlonjs
A new, open source, extensible, platform-agnostic tool for remotely debugging and testing your JavaScript. Powered by node.js and socket.io
Stars: ✭ 2,893 (+933.21%)
Mutual labels:  socket
echo-server
Echo Server is a container-ready, multi-scalable Node.js application used to host your own Socket.IO server for Laravel Broadcasting.
Stars: ✭ 36 (-87.14%)
Mutual labels:  socket
Network
Low-level networking interface
Stars: ✭ 255 (-8.93%)
Mutual labels:  socket
python
一个有深度的Python系列博客 🐍
Stars: ✭ 13 (-95.36%)
Mutual labels:  socket
slsk-client
🐦 Soulseek client for NodeJS
Stars: ✭ 110 (-60.71%)
Mutual labels:  socket
core
Certified HOOBS Stack
Stars: ✭ 30 (-89.29%)
Mutual labels:  socket
socket-chat
This project will help you build a chat app by using the Socket IO library.
Stars: ✭ 36 (-87.14%)
Mutual labels:  socket
Aiowebsocket
Async WebSocket Client. Advantage: Flexible Lighter and Faster
Stars: ✭ 263 (-6.07%)
Mutual labels:  socket
ng-terminal
NgTerminal is a terminal component on Angular 12. the Ivy distribution's released from v5.0.0.
Stars: ✭ 87 (-68.93%)
Mutual labels:  telnet
extension-networking
Library developed for OpenFL to facilitate connections between applications, using TCP sockets, and following the scheme of event-driven programming.
Stars: ✭ 29 (-89.64%)
Mutual labels:  socket
dankdomain
🏰 Ɗaɳƙ Ɗoɱaiɳ :: the return of Hack & Slash
Stars: ✭ 25 (-91.07%)
Mutual labels:  telnet
Hisocket
It is a lightweight client socket solution, you can used it in C# project or Unity3d
Stars: ✭ 275 (-1.79%)
Mutual labels:  socket

GitHub license Build Status npm Donate Bitcoin/Altcoins
npm version

node-telnet-client

A simple telnet client for Node.js

Installation

Locally in your project or globally:

npm install telnet-client
npm install -g telnet-client

Quick start

Async/Await (Node.js >= 7.6.0)

'use strict'

const Telnet = require('telnet-client')

async function run() {
  let connection = new Telnet()

  // these parameters are just examples and most probably won't work for your use-case.
  let params = {
    host: '127.0.0.1',
    port: 23,
    shellPrompt: '/ # ', // or negotiationMandatory: false
    timeout: 1500
  }

  try {
    await connection.connect(params)
  } catch(error) {
    // handle the throw (timeout)
  }

  let res = await connection.exec('uptime')
  console.log('async result:', res)
}

run()

Callback-style

var Telnet = require('telnet-client')
var connection = new Telnet()

// these parameters are just examples and most probably won't work for your use-case.
var params = {
  host: '127.0.0.1',
  port: 23,
  shellPrompt: '/ # ', // or negotiationMandatory: false
  timeout: 1500,
  // removeEcho: 4
}

connection.on('ready', function(prompt) {
  connection.exec(cmd, function(err, response) {
    console.log(response)
  })
})

connection.on('timeout', function() {
  console.log('socket timeout!')
  connection.end()
})

connection.on('close', function() {
  console.log('connection closed')
})

connection.connect(params)

Promises

var Telnet = require('telnet-client')
var connection = new Telnet()

// these parameters are just examples and most probably won't work for your use-case.
var params = {
  host: '127.0.0.1',
  port: 23,
  shellPrompt: '/ # ', // or negotiationMandatory: false
  timeout: 1500,
  // removeEcho: 4
}

connection.connect(params)
.then(function(prompt) {
  connection.exec(cmd)
  .then(function(res) {
    console.log('promises result:', res)
  })
}, function(error) {
  console.log('promises reject:', error)
})
.catch(function(error) {
  // handle the throw (timeout)
})

Generators

var co = require('co')
var bluebird = require('bluebird')
var Telnet = require('telnet-client')
var connection = new Telnet()

// these parameters are just examples and most probably won't work for your use-case.
var params = {
  host: '127.0.0.1',
  port: 23,
  shellPrompt: '/ # ', // or negotiationMandatory: false
  timeout: 1500,
  // removeEcho: 4
}

// using 'co'
co(function*() {
  try {
    yield connection.connect(params)
  } catch (error) {
    // handle the throw (timeout)
  }

  let res = yield connection.exec(cmd)
  console.log('coroutine result:', res)
})

// using 'bluebird'
bluebird.coroutine(function*() {
  try {
    yield connection.connect(params)
  } catch (error) {
    // handle the throw (timeout)
  }

  let res = yield connection.exec(cmd)
  console.log('coroutine result:', res)
})()

Async/Await (using babeljs)

'use strict'

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

require('babel-runtime/core-js/promise').default = Promise

Promise.onPossiblyUnhandledRejection(function(error) {
  throw error
})

// also requires additional babeljs setup

async function run() {
  let connection = new Telnet()

  // these parameters are just examples and most probably won't work for your use-case.
  let params = {
    host: '127.0.0.1',
    port: 23,
    shellPrompt: '/ # ', // or negotiationMandatory: false
    timeout: 1500
  }

  try {
    await connection.connect(params)
  } catch (error) {
    // handle the throw (timeout)
  }

  let res = await connection.exec(cmd)
  console.log('async result:', res)
}

run()

Problems?

Please do not directly email any node-telnet-client committers with questions or problems. A community is best served when discussions are held in public.

If you have a problem, please search the issues to see if there's existing reports to the issue you're facing and if there's any known solutions.

I also offer professional (paid) support and services, so make sure to contact me for more info.

API

var Telnet = require('telnet-client')
var connection = new Telnet()

connection.connect(options) -> Promise

Creates a new TCP connection to the specified host, where 'options' is an object which can include following properties:

  • host: Host the client should connect to. Defaults to '127.0.0.1'.
  • port: Port the client should connect to. Defaults to '23'.
  • localAddress: Local interface to bind for network connections. Defaults to an empty string. More information can be found here.
  • socketConnectOptions: Allows to pass an object, which can contain every property from Node's SocketConnectOpts. Defaults to an empty object. Properties defined inside this object will overwrite any of the three above properties. More information can be found here.
  • timeout: Sets the socket to timeout after the specified number of milliseconds. of inactivity on the socket.
  • shellPrompt: Shell prompt that the host is using. Can be a string or an instance of RegExp. Defaults to regex '/(?:/ )?#\s/'. Use negotiationMandatory: false if you don't need this.
  • loginPrompt: Username/login prompt that the host is using. Can be a string or an instance of RegExp. Defaults to regex '/login[: ]*$/i'.
  • passwordPrompt: Password/login prompt that the host is using. Can be a string or an instance of RegExp. Defaults to regex '/Password: /i'.
  • failedLoginMatch: String or regex to match if your host provides login failure messages. Defaults to undefined.
  • initialCTRLC: Flag used to determine if an initial 0x03 (CTRL+C) should be sent when connected to server.
  • initialLFCR: Flag used to determine if an initial '\r\n' (CR+LF) should be sent when connected to server.
  • username: Username used to login. Defaults to 'root'.
  • password: Password used to login. Defaults to 'guest'.
  • sock: Duplex stream which can be used for connection hopping/reusing.
  • irs: Input record separator. A separator used to distinguish between lines of the response. Defaults to '\r\n'.
  • ors: Output record separator. A separator used to execute commands (break lines on input). Defaults to '\n'.
  • echoLines: The number of lines used to cut off the response. Defaults to 1.
  • stripShellPrompt: Whether shell prompt should be excluded from the results. Defaults to true.
  • pageSeparator: The pattern used (and removed from final output) for breaking the number of lines on output. Defaults to '---- More'.
  • negotiationMandatory: Disable telnet negotiations if needed. Can be used with 'send' when telnet specification is not needed. Telnet client will then basically act like a simple TCP client. Defaults to true.
  • execTimeout: A timeout used to wait for a server reply when the 'exec' method is used. Defaults to 2000 (ms).
  • sendTimeout: A timeout used to wait for a server reply when the 'send' method is used. Defaults to 2000 (ms).
  • maxBufferLength: Maximum buffer length in bytes which can be filled with response data. Defaults to 1M.
  • debug: Enable/disable debug logs on console. Defaults to false.

Resolves once the connection is ready (analogous to the ready event). Rejects if the timeout is hit.

connection.exec(data, [options], [callback]) -> Promise

Sends data on the socket (should be a compatible remote host's command if sane information is wanted). The optional callback parameter will be executed with an error and response when the command is finally written out and the response data has been received.
If there was no error when executing the command, 'error' as the first argument to the callback will be undefined. Command result will be passed as the second argument to the callback.

*** important notice/API change from 0.3.0 ***
The callback argument is now called with a signature of (error, [response])

Options:

  • shellPrompt: Shell prompt that the host is using. Can be a string or an instance of RegExp. Defaults to regex '/(?:/ )?#\s/'.
  • loginPrompt: Username/login prompt that the host is using. Can be a string or an instance of RegExp. Defaults to regex '/login[: ]*$/i'.
  • failedLoginMatch: String or regex to match if your host provides login failure messages. Defaults to undefined.
  • timeout: Sets the socket to timeout after the specified number of milliseconds of inactivity on the socket.
  • execTimeout: A timeout used to wait for a server reply when this method is used. Defaults to 'undefined'.
  • maxBufferLength: Maximum buffer length in bytes which can be filled with response data. Defaults to 1M.
  • irs: Input record separator. A separator used to distinguish between lines of the response. Defaults to '\r\n'.
  • ors: Output record separator. A separator used to execute commands (break lines on input). Defaults to '\n'.
  • echoLines: The number of lines used to cut off the response. Defaults to 1.

connection.send(data, [options], [callback]) -> Promise

Sends data on the socket without requiring telnet negotiations.

Options:

  • ors: Output record separator. A separator used to execute commands (break lines on input). Defaults to '\n'.
  • waitfor: Wait for the given string or RegExp before returning a response. If not defined, the timeout value will be used.
  • timeout: A timeout used to wait for a server reply when the 'send' method is used. Defaults to 2000 (ms) or to sendTimeout ('connect' method) if set.
  • maxBufferLength: Maximum buffer length in bytes which can be filled with response data. Defaults to 1M.

connection.shell(callback) -> Promise

Starts an interactive shell session. Returns a duplex stream which can be used to read and write data.

connection.getSocket() -> net.Socket

Returns a duplex stream that can be used for connection hopping. See 'sock' option.

connection.end() -> Promise

Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.

connection.destroy() -> Promise

Ensures that no more I/O activity happens on this socket. Only necessary in case of errors (parse error or so).

Event: 'connect'

Emitted when a socket connection is successfully established.

Event: 'ready'

Emitted when a socket connection is successfully established and the client is successfully connected to the specified remote host. A value of prompt is passed as the first argument to the callback.

Event: 'writedone'

Emitted when the write of given data is sent to the socket.

Event: 'data'

This is a forwarded 'data' event from core 'net' library. A <buffer> is received when this event is triggered.

Event: 'timeout'

Emitted if the socket times out from inactivity. This is only to notify that the socket has been idle. The user must manually close the connection.

Event: 'failedlogin'

Emitted when the failedLoginMatch pattern is provided and a match is found from the host. The 'destroy()' method is called directly following this event.

Event: 'error'

Emitted when an error occurs. The 'close' event will be called directly following this event.

Event: 'end'

Emitted when the other end of the socket (remote host) sends a FIN packet.

Event: 'close'

Emitted once the socket is fully closed.

Professional support

I offer professional support for node-telnet-client and beyond. I have many years of expertise on building robust, scalable Node.js applications and can help you overcome issues and challenges preventing you to ship your great products. I also excel in software architecture and implementation, being able to provide you with development, planning, consulting, training and customization services. Feel free to contact me so we can discuss how to help you finish your products!

Sponsors

Become a sponsor and get your logo on project's README on GitHub with a link to your site. Feel free to contact me for the arrangement!

Donate

If you love this project, consider donating!

License

This library is licensed under LGPLv3. Please see LICENSE for licensing details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].