Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Find open ports programmatically with Node.js

branch: master

Update README.md

Changed all "doors" to "ports"
latest commit 89382041fb
alanhoff alanhoff authored November 27, 2012
Octocat-spinner-32 bin Initial commit. July 16, 2012
Octocat-spinner-32 example Initial commit. July 16, 2012
Octocat-spinner-32 lib Initial commit. July 16, 2012
Octocat-spinner-32 test Initial commit. July 16, 2012
Octocat-spinner-32 .gitignore Initial commit. July 16, 2012
Octocat-spinner-32 .npmignore Initial commit. July 16, 2012
Octocat-spinner-32 LICENSE Initial commit. July 16, 2012
Octocat-spinner-32 README.md Update README.md November 27, 2012
Octocat-spinner-32 app.js Initial commit. July 16, 2012
Octocat-spinner-32 package.json Initial commit. July 16, 2012
README.md

Portastic

Programmatically find open ports with Node.js

Installation

To install Portastic you can simply use NPM:

npm install portastic

Usage

Finding all opened ports within a range:

port = require('portastic');

options = {
    min : 8000,
    max : 8005
}

port.find(options, function(err, data){
    if(err)
        throw err;
    console.log(data);
});

If you wan't to retrieve just one or more ports you can pass it in the options:

options = {
    min : 8000,
    max : 8005,
    retrieve : 1
}

You can also test ports:

port.test(80, function(err, data){
    if(err)
        throw err;

    if(data == false)
        console.log('The port isn\'t opened.');
    else
        console.log('The port is opened!');
});

If you wan't to test an array of ports, you sure can:

port.test([80, 93, 8001, 22], function(err, data){
    if(err)
        throw err;

    // 'data' will be an array with the opened ports only
    console.log('Opened ports:', data);
});

Command line

You can use Portastic in the command line too:

npm install -g portastic

This will install portastic globally, now it's up to you to call it. Display the help with:

portastic -h

Tests

If you wan't to run tests on portastic locally you will need to follow this steps:

cd /path/to/portastic/folder
npm install vows
npm test
Something went wrong with that request. Please try again.