Gathering detailed insights and metrics for telnetlib
Gathering detailed insights and metrics for telnetlib
npm install telnetlib
Typescript
Module System
Node Version
NPM Version
73.3
Supply Chain
99.4
Quality
75.6
Maintenance
100
Vulnerability
100
License
JavaScript (99.85%)
Shell (0.15%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
6,729
Last Day
2
Last Week
15
Last Month
139
Last Year
1,972
MIT License
20 Stars
54 Commits
2 Forks
2 Watchers
2 Branches
1 Contributors
Updated on Jan 15, 2025
Minified
Minified + Gzipped
Latest Version
1.0.2
Package Id
telnetlib@1.0.2
Unpacked Size
39.53 kB
Size
9.07 kB
File Count
14
NPM Version
6.14.17
Node Version
14.19.3
Cumulative downloads
Total Downloads
Last Day
-66.7%
2
Compared to previous day
Last Week
-50%
15
Compared to previous week
Last Month
-21.5%
139
Compared to previous month
Last Year
16.3%
1,972
Compared to previous year
A simple Node.js telnet server/client library. It provides an interface similar to the standard net module (viz. createServer
and createConnection
) while abstracting option negotiation and providing handlers for some common options.
This example is a server that, once option negotiation finishes, says hello world to the client and then echos anything it receives back to the client. The client portion simply echos anything back to the server.
1const telnetlib = require('telnetlib'); 2 3const server = telnetlib.createServer({}, (c) => { 4 c.on('negotiated', () => { 5 c.write('Hello World!'); 6 }); 7 8 c.on('data', (data) => { 9 c.write(data); 10 }); 11}); 12 13server.listen(9001);
1const telnetlib = require('telnetlib'); 2 3const client = telnetlib.createConnection( 4 { 5 host: '127.0.0.1', 6 port: 9001 7 }, 8 () => { 9 client.on('data', (data) => { 10 client.write(data); 11 }); 12 } 13);
telnetlib.createServer(options, handler)
options
Object
remoteOptions
Array Option codes we want enabled remotelylocalOptions
Array Option codes we want enabled locallyreceiveBuffermax
integer How large the receive buffer issubnegotiationBufferMax
integer How large the subnegotiation buffer ishandler
Function listener for the connection
event.Creates a new telnet server.
telnetlib.createConnection(options, handler)
options
Object
host
String Host the socket should connect toport
Integer Port the socket should connect toremoteOptions
Array Option codes we want enabled remotelylocalOptions
Array Option codes we want enabled locallyreceiveBuffermax
integer How large the receive buffer issubnegotiationBufferMax
integer How large the subnegotiation buffer ishandler
Function listener for the connect
event.A factory function which creates a net.Socket
, wraps it in a TelnetSocket
, initiates option negotiation, and returns the TelnetSocket
.
telnetlib.defineOption(name, code[, handler])
name
String The name of the telnet option.code
Integer The telnet option codehandler
TelnetOption Optional class that manages optionRegister an option handler with the library.
telnetlib.TelnetSocket
This class wraps a socket and manages object negotiation.
new telnetlib.TelnetSocket(socket[, options])
socket
net.Socket Socket object to wrapoptions
Object
remoteOptions
Array Option codes we want enabled remotelylocalOptions
Array Option codes we want enabled locallyreceiveBuffermax
integer How large the receive buffer issubnegotiationBufferMax
integer How large the subnegotiation buffer isnegotiated
Emitted when all option negotiations have been settled either through (dis)agreement or timeout.
enable
optionCode
integer telnet option codeat
String value indicating where the option was enabled. Either 'LOCAL'
or 'REMOTE'
Emitted when an option is enabled.
disable
optionCode
integer telnet option codeat
String value indicating where the option was disabled. Either 'LOCAL'
or 'REMOTE'
Emitted when an option is disabled.
TelnetSocket.enableRemote(option[, timeout])
option
- integer telnet option codetimeout
- integer timeout in millisecondsRequest that an option be enabled remotely.
TelnetSocket.disableRemote(option[, timeout])
option
- integer telnet option codetimeout
- integer timeout in millisecondsRequest that an option be disabled remotely.
TelnetSocket.enableLocal(option[, timeout])
option
- integer telnet option codetimeout
- integer timeout in millisecondsRequest that an option be enabled locally.
TelnetSocket.disableLocal(option[, timeout])
option
- integer telnet option codetimeout
- integer timeout in millisecondsRequest that an option be disabled locally.
TelnetSocket.getOption(code)
code
- integer telnet option codeGet the handler for the specified option.
telnetlib.TelnetOption
This is the base class for option handlers.
enabled(at)
at
String value indicating where option was enabled. Either 'LOCAL'
or 'REMOTE'
Called whenever the option is enabled. Intended to be overridden by subclasses.
disabled(at)
at
String value indicating where option was disabled. Either 'LOCAL'
or 'REMOTE'
Called whenever the option is disabled. Intended to be overridden by subclasses.
subnegotiation(buffer)
buffer
Buffer contents of the subnegotiationCalled when a subnegotiation is received for an option. Intended to be overridden by subclasses.
GMCP
telnetlib.TelnetOption
This class handles sending and receiving GMCP message.
gmcp
packageName
String the name of the package the message belongs tomessageName
String the name of the messagedata
String | Number | Boolean | Object | Array The message dataEmitted when a GMCP message is received. packageName
and messageName
are normalized to lower case.
gmcp/<name>
data
String | Number | Boolean | Object | Array The message dataAs above, but instead of having packageName
and messageName
values they are included in the event name.
send(packageName, messageName[, data])
packageName
String the name of the packagemessageName
String the name of the messagedata
String | Number | Boolean | Object | Array The message dataSend a GMCP message.
MCCP
telnetlib.TelnetOption
This class handles MCCP2 compression.
endCompression([callback])
callback
Function optional callbackOnly valid when MCCP is enabled locally. Sends a Z_FINISH
flush and forces MCCP off locally.
NAWS
telnetlib.TelnetOption
This class handles sending and receiving window resize events.
resize
data
Objectwidth
Integer The width reported by the client.
height
Integer The height reported by the client.Event emitted when a resize subnegotiation is received.
sendResize([width[, height]])
width
Integer The width to send. Default: 80height
Integer The height to send. Default: 24Send a resize subnegotiation.
The main reason to extend this library would be to add additional option handlers. This can be easily done by subclassing TelnetOption
and registering it with the library using telnetlib.defineOption
before creating a server or client. As in:
1const telnetlib = require('telnetlib'); 2const { where } = telnetlib.constants; 3 4const ourOptionCode = 123; 5class Something extends telnetlib.TelnetOption { 6 constructor(socket, code) { 7 super(socket, ourOptionCode); 8 } 9 10 enabled(at) { 11 if (at == where.LOCAL) console.log('this option was enabled locally'); 12 } 13 14 disabled(at) { 15 if (at == where.LOCAL) console.log('this option was disabled locally'); 16 } 17 18 subnegotiation(buffer) {} 19} 20 21telnetlib.defineOption('Something', ourOptionCode, Something);
This is similar to the simple example above, but instead of sending normal text back and forth across the connection, the same thing is done with GMCP messages.
1const telnetlib = require('telnetlib'); 2const { GMCP } = telnetlib.options; 3 4const server = telnetlib.createServer( 5 { 6 localOptions: [GMCP] 7 }, 8 (c) => { 9 const gmcp = c.getOption(GMCP); 10 c.on('negotiated', () => { 11 gmcp.send('herp', 'derp', 42); 12 }); 13 14 gmcp.on('gmcp/herp.derp', (data) => { 15 gmcp.send('herp', 'derp', data); 16 }); 17 } 18); 19 20server.listen(9001);
1const telnetlib = require('telnetlib'); 2const { GMCP } = telnetlib.options; 3 4const client = telnetlib.createConnection( 5 { 6 host: '127.0.0.1', 7 port: 9001, 8 remoteOptions: [GMCP] 9 }, 10 () => { 11 const gmcp = client.getOption(GMCP); 12 gmcp.on('gmcp/herp.derp', (data) => { 13 gmcp.send('herp', 'derp', data); 14 }); 15 } 16);
Using the blessed library this example renders a box with in the middle of the terminal. The box will resize to fit in clients that support NAWS.
1const blessed = require('blessed'); 2const telnetlib = require('telnetlib'); 3const { ECHO, TRANSMIT_BINARY, NAWS, SGA } = telnetlib.options; 4 5const server = telnetlib.createServer( 6 { 7 remoteOptions: [NAWS, TRANSMIT_BINARY, SGA], 8 localOptions: [ECHO, TRANSMIT_BINARY, SGA] 9 }, 10 (c) => { 11 let screen; 12 13 c.on('negotiated', () => { 14 screen = blessed.screen({ 15 smartCSR: true, 16 input: c, 17 output: c, 18 height: 80, 19 width: 24, 20 terminal: 'xterm', 21 fullUnicode: true, 22 cursor: { 23 artificial: true, 24 shape: 'line', 25 blink: true, 26 color: null 27 } 28 }); 29 30 const box = blessed.box({ 31 parent: screen, 32 top: 'center', 33 left: 'center', 34 width: '50%', 35 height: '50%', 36 content: 'Hello World', 37 border: 'line' 38 }); 39 40 screen.render(); 41 }); 42 43 c.on('end', () => { 44 if (screen) screen.destroy(); 45 }); 46 } 47); 48 49server.listen(9001);
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
14 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-03-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More