Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
containernet
Advanced tools
Spin up and interact with virtual networks using Containernet and Node.js
Spin up and interact with virtual networks using Containernet and Node.js
npm install containernet
This module is a fork of @mafintosh mininet altered to work with Containernet
var containernet = require('containernet')
var cn = containernet()
var s1 = cn.createSwitch()
var d1 = cn.createHost({image: 'ubuntu:trusty', cmd: '/bin/bash'})
var d2 = cn.createHost({image: 'ubuntu:trusty', cmd: '/bin/bash'})
d1.link(s1)
d2.link(s1)
cn.start(function () {
console.log('containernet started')
console.log(`d2 ${d2.ip} ${d2.mac}`)
// Test connectivity
d1.exec(`ping -c 2 ${d2.ip}`, function (err, stream) {
if (err) {
console.log(err)
} else {
stream.pipe(process.stdout)
}
// Stop containernet
cn.stop()
})
})
process.on('SIGINT', function () {
cn.stop()
})
var cn = containernet([options])
Create a new containernet instance. Options include
{
clean: false, // if true run mn -c first
sudo: true, // use sudo if needed
sock: '/tmp/mn.sock', // explictly set the .sock file used
debug: false, // set to true to enable debug output
}
If for some reason your containernet instance stops working
you probably wanna try using clean: true
.
cn.start([callback])
Start the containernet network. Usually you call this after defining your hosts, switches and links.
After the network has fully started start
is emitted.
cn.stop([callback])
Stop the containernet network. You should not call any other methods after this.
After the network has fully stopped stop
is emitted.
cn.switches
Array of all created switches.
cn.hosts
Array of all created hosts.
var sw = cn.createSwitch()
Create a new switch
sw.link(other, [options])
Link the switch with another switch or host. Options include:
{
bandwidth: 10, // use 10mbit link
delay: '100ms', // 100ms delay
loss: 10, // 10% package loss
htb: true // use htb
}
var host = cn.createHost([options])
Create a new host. Options include
{
image: 'alpine', // docker image to use for the host
cmd: '/bin/bash' // cmd to run on the newly created container
}
host.ip
The IP address of the host. Populated after the network is started.
host.mac
The MAC address of the host. Populated after the network is started.
host.link(other, [options])
Link the host with another host or switch.
Takes the same options as sw.link
.
host.exec(cmd, [callback])
Execute a docker exec command and return the stream in the callback.
MIT
FAQs
Spin up and interact with virtual networks using Containernet and Node.js
The npm package containernet receives a total of 1 weekly downloads. As such, containernet popularity was classified as not popular.
We found that containernet demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.