New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

expectly

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expectly

Remote CLI for Cisco IOS and Adtran AOS.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

expectly

Node script utility for Cisco equipment. (Unstable)

Settings

var settings = {
	host: 'switch1',
	port: 22,
	protocol: 'ssh',
	username: 'cisco',
	password: 'cisco',
	autoEnable: true,
	enablePassword: 'cisco'
}

To connect to a device with telnet set the protocol to raw and port number to 23.

Expectly Methods

  • .connect() - Connects to the remote host.

  • .end() - Closes the connection to the remote host.

Expectly Events

Event: 'connect'

A connection was made to the remote host. The session variable is the expectly session for this connection.

  • session - An expecly-stream object for this connection.

Event: 'ready'

Emitted after the session is logged in and the enable command is issued if requested.

  • session - An expecly-stream object for this connection.

Event: 'error'

  • err - Error events are emitted using this event.

Example

var Expectly = require('expectly').Expectly;
var Patterns = require('expectly').Patterns;

var settings = {
	host: 'switch1',
	port: 22,
	protocol: 'ssh',
	username: 'cisco',
	password: 'cisco',
	autoEnable: true,
	enablePassword: 'cisco'
}

// These regexs are used to grab the content between the begin and start of a config.
var START_CONFIG = Patterns['RANGE START RUNNING-CONFIG'];
var END_CONFIG = Patterns['RANGE STOP RUNNING-CONFIG'];


var expectly = new Expectly(settings);

// Show errors...
expectly.on('error', function(err){
	console.log('Error', err)
});

expectly.on('ready', function(session){

	// At this point you should be logged in. The session object is an expectly-stream session.

	// Here we execute a 'show run' command to see 

	session.sync()
		.send("show run\n")
		.between(BEGIN_CONFIG, END_CONFIG, function(err, results, done) {
			// Store the configuration in the sessions config variable.
			session.set('config', results);
			done();
		})
		.end(function(err){
			// Get the configuration from the sessions config variable	
			var deviceConfig = session.get('config');
			console.log(deviceConfig);
			expectly.end();
	})
})

expectly.connect();

Tricks

These tricks assume

  • To grab running configurations from equipment use the .between() feature and these regular expressions:
var START_CONFIG = Patterns['RANGE_START_RUNNING-CONFIG'];
var END_CONFIG = Patterns['RANGE_STOP_RUNNING-CONFIG'];

session.sync()
	.send("show running-config\n")
	.between(START_CONFIG, END_CONFIG, function(err, results, done) {
		// Store the configuration in the sessions config variable.
		session.set('config', results);
		done();
	})
	.end(function(err){
		// Get the configuration from the sessions config variable	
		var deviceConfig = session.get('config');
		console.log(deviceConfig);
		expectly.end();
	})

  • To monitor what is going during the session:
var expectly = new Expectly(settings);
expectly.on('connect', function(session) {
    // Use the connection object to listen for data.
	expectly.connection.on('data', function(data) {
		console.log('>>>', data.toString())
	});
});

Patterns

There is a patterns object included in the module which contains some cisco related regexes. These can be used with the expect, match and between functions of the expectly-stream object.

var Patterns = require('expectly').Patterns;
var PATTERN_PROMPT = Patterns['PROMPT_CLI'];

AliasPurposeExample
PROMPT_USERNAMEMatch user name prompts.Username:
PROMPT_PASSWORDMatch password prompts.Password:
PROMPT_CLIMatch the host> or host# prompts.switch1>
RANGE_START_RUNNING-CONFIGMatch the begining of a running-config.Building configuration...
RANGE_STOP_RUNNING-CONFIGMatch the begining of a running-config.end ... switch

Keywords

FAQs

Package last updated on 06 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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