Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

telnet-client

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telnet-client - npm Package Compare versions

Comparing version 0.4.3 to 0.5.0

test/001_generic.js

50

lib/telnet-client.js

@@ -27,6 +27,6 @@ // Node.js Telnet client

// Set prompt regex defaults
self.shellPrompt = checkRegExp(opts.shellPrompt, /(?:\/ )?#\s/)
self.loginPrompt = checkRegExp(opts.loginPrompt, /login[: ]*$/i)
self.passwordPrompt = checkRegExp(opts.passwordPrompt, /Password: /i)
self.failedLoginPrompt = checkRegExp(opts.failedLoginPrompt, undefined)
self.shellPrompt = (typeof opts.shellPrompt !== 'undefined' ? opts.shellPrompt : /(?:\/ )?#\s/)
self.loginPrompt = (typeof opts.loginPrompt !== 'undefined' ? opts.loginPrompt : /login[: ]*$/i)
self.passwordPrompt = (typeof opts.passwordPrompt !== 'undefined' ? opts.passwordPrompt : /Password: /i)
self.failedLoginPrompt = opts.failedLoginPrompt

@@ -91,5 +91,5 @@ self.debug = (typeof opts.debug !== 'undefined' ? opts.debug : false)

if (opts && opts instanceof Object) {
self.shellPrompt = checkRegExp(opts.shellPrompt, self.shellPrompt)
self.loginPrompt = checkRegExp(opts.loginPrompt, self.loginPrompt)
self.failedLoginPrompt = checkRegExp(opts.failedLoginPrompt, self.failedLoginPrompt)
self.shellPrompt = opts.shellPrompt || self.shellPrompt
self.loginPrompt = opts.loginPrompt || self.loginPrompt
self.failedLoginPrompt = opts.failedLoginPrompt || self.failedLoginPrompt
self.timeout = opts.timeout || self.timeout

@@ -156,3 +156,3 @@ self.irs = opts.irs || self.irs

var promptIndex = stringData.search(telnetObj.shellPrompt)
var promptIndex = search(stringData, telnetObj.shellPrompt)

@@ -167,11 +167,11 @@ if (promptIndex !== -1) {

}
else if (stringData.search(telnetObj.loginPrompt) !== -1) {
else if (search(stringData, telnetObj.loginPrompt) !== -1) {
telnetObj.telnetState = 'login'
login(telnetObj, 'username')
}
else if (stringData.search(telnetObj.passwordPrompt) !== -1) {
else if (search(stringData, telnetObj.passwordPrompt) !== -1) {
telnetObj.telnetState = 'login'
login(telnetObj, 'password')
}
else if (typeof telnetObj.failedLoginPrompt !== 'undefined' && stringData.search(telnetObj.failedLoginPrompt) !== -1) {
else if (typeof telnetObj.failedLoginPrompt !== 'undefined' && search(stringData, telnetObj.failedLoginPrompt) !== -1) {
telnetObj.telnetState = 'failedlogin'

@@ -188,3 +188,3 @@ telnetObj.emit('failedlogin', stringData)

if (promptIndex === -1 && stringData.length !== 0) {
if (stringData.search(telnetObj.pageSeparator) !== -1) {
if (search(stringData, telnetObj.pageSeparator) !== -1) {
telnetObj.telnetSocket.write(Buffer('20', 'hex'))

@@ -198,3 +198,3 @@ }

for (var i = 0; i < telnetObj.cmdOutput.length; i++) {
if (telnetObj.cmdOutput[i].search(telnetObj.pageSeparator) !== -1) {
if (search(telnetObj.cmdOutput[i], telnetObj.pageSeparator) !== -1) {
telnetObj.cmdOutput[i] = telnetObj.cmdOutput[i].replace(telnetObj.pageSeparator, '')

@@ -245,25 +245,7 @@ if (telnetObj.cmdOutput[i].length === 0) telnetObj.cmdOutput.splice(i, 1)

function checkRegExp(str, def){
if (!str) {
return def
}
if (str instanceof RegExp) {
// if they sent a regex obj, use it
return str
}
else {
// otherwise, convert their string to the equivalent regex
try {
return new RegExp(
str.toString()
.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'))
}
catch(error) {
if (self.debug) console.error('Invalid RegExp:', str)
}
}
return def
function search(str, pattern){
if (pattern instanceof RegExp) return str.search(pattern)
else return str.indexOf(pattern)
}
module.exports = Telnet
{
"name": "telnet-client",
"description": "Simple node.js telnet client",
"description": "A simple node.js telnet client",
"author": {

@@ -8,3 +8,3 @@ "name": "Mario Kozjak",

},
"version": "0.4.3",
"version": "0.5.0",
"main": "./lib/telnet-client.js",

@@ -19,3 +19,4 @@ "engine": "node >= 0.10.29",

"jscoverage": "^0.6.x",
"nodeunit": ">= 0.9.x"
"nodeunit": ">= 0.9.x",
"telnet": "0.0.1"
},

@@ -34,4 +35,19 @@ "scripts": {

"email": "petar.koretic@gmail.com"
},
{
"name": "stardast"
},
{
"name": "ChristopherHackett"
},
{
"name": "EyePulp"
},
{
"name": "HaykoKoryun"
},
{
"name": "silverwind"
}
]
}

@@ -126,5 +126,5 @@ [![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/mkozjak/node-telnet-client/blob/master/LICENSE)

of inactivity on the socket.
* `shellPrompt`: Shell prompt that the host is using. Defaults to regex '/(?:\/ )?#\s/'.
* `loginPrompt`: Username/login prompt that the host is using. Defaults to regex '/login[: ]*$/i'.
* `passwordPrompt`: Username/login prompt that the host is using. Defaults to regex '/Password: /i'.
* `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'.
* `passwordPrompt`: Username/login prompt that the host is using. Can be a string or an instance of RegExp. Defaults to regex '/Password: /i'.
* `loginFailedPrompt`: String or regex to match if your host provides login failure messages. Defaults to undefined.

@@ -151,4 +151,4 @@ * `username`: Username used to login. Defaults to 'root'.

* `shellPrompt`: Shell prompt that the host is using. Defaults to regex '/(?:\/ )?#\s/'.
* `loginPrompt`: Username/login prompt that the host is using. Defaults to regex '/login[: ]*$/i'.
* `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'.
* `loginFailedPrompt`: String or regex to match if your host provides login failure messages. Defaults to undefined.

@@ -155,0 +155,0 @@ * `timeout`: Sets the socket to timeout after the specified number of milliseconds

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc