Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
portscanner
Advanced tools
The portscanner npm package is a utility for scanning and checking the status of ports on a given host. It can be used to find open ports, check if a specific port is open, and find the first open port within a range.
Check if a specific port is open
This feature allows you to check if a specific port on a given host is open or closed. The code sample demonstrates how to check the status of port 3000 on localhost.
const portscanner = require('portscanner');
portscanner.checkPortStatus(3000, '127.0.0.1', (error, status) => {
if (error) throw error;
console.log(`Port 3000 is ${status}`); // 'open' or 'closed'
});
Find the first open port in a range
This feature allows you to find the first open port within a specified range on a given host. The code sample demonstrates how to find the first open port between 3000 and 3010 on localhost.
const portscanner = require('portscanner');
portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', (error, port) => {
if (error) throw error;
console.log(`First open port is ${port}`);
});
Find the first port in use in a range
This feature allows you to find the first port that is in use within a specified range on a given host. The code sample demonstrates how to find the first port in use between 3000 and 3010 on localhost.
const portscanner = require('portscanner');
portscanner.findAPortInUse(3000, 3010, '127.0.0.1', (error, port) => {
if (error) throw error;
console.log(`First port in use is ${port}`);
});
net-ping is a package that provides network utilities including ping and port scanning. While it offers more comprehensive network diagnostic tools, its port scanning capabilities are similar to those of portscanner. It can be used to check the status of ports and find open ports on a host.
The portscanner module is an asynchronous JavaScript port scanner for Node.js.
Portscanner can check a port, or range of ports, for 'open' or 'closed' statuses.
npm install portscanner
A brief example:
var portscanner = require('portscanner')
// Checks the status of a single port
portscanner.checkPortStatus(3000, '127.0.0.1', function(error, status) {
// Status is 'open' if currently in use or 'closed' if available
console.log(status)
})
// Find the first available port. Asynchronously checks, so first port
// determined as available is returned.
portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', function(error, port) {
console.log('AVAILABLE PORT AT: ' + port)
})
// Find the first port in use or blocked. Asynchronously checks, so first port
// to respond is returned.
portscanner.findAPortInUse(3000, 3010, '127.0.0.1', function(error, port) {
console.log('PORT IN USE AT: ' + port)
})
// You can also pass array of ports to check
portscanner.findAPortInUse([3000, 3005, 3006], '127.0.0.1', function(error, port) {
console.log('PORT IN USE AT: ' + port)
})
// And skip host param. Default is '127.0.0.1'
portscanner.findAPortNotInUse(3000, 4000, function(error, port) {
console.log('PORT IN USE AT: ' + port)
})
// And use promises
portscanner.findAPortNotInUse(3000, 4000).then(function(port) {
console.log('PORT IN USE AT: ' + port)
})
The example directory contains a more detailed example.
npm test
Please create issues or pull requests for port scanning related features you'd like to see included.
FAQs
Asynchronous port scanner for Node.js
The npm package portscanner receives a total of 1,077,414 weekly downloads. As such, portscanner popularity was classified as popular.
We found that portscanner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.