What is portscanner?
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.
What are portscanner's main functionalities?
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}`);
});
Other packages similar to portscanner
net-ping
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 What
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.
The How
To Install
npm install portscanner
To Use
A brief example:
var portscanner = require('portscanner')
portscanner.checkPortStatus(3000, '127.0.0.1', function(error, status) {
console.log(status)
})
portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', function(error, port) {
console.log('AVAILABLE PORT AT: ' + port)
})
portscanner.findAPortInUse(3000, 3010, '127.0.0.1', function(error, port) {
console.log('PORT IN USE AT: ' + port)
})
The example directory contains a more detailed example.
To Test
Bleh. I am a fan of testing, but currently looking into an easier way to test
several HTTP connections. If any ideas, please message me.
The Future
Please create issues, or better yet, pull requests, for port scanning related
features you'd like to see included.
The License (MIT)
Released under the MIT license. See the LICENSE file for the complete wording.