portscanner
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -48,13 +48,25 @@ var net = require('net') | ||
* | ||
* @param {Number} port - Port to check status on. | ||
* @param {String} host - Where to scan. Defaults to 'localhost'. | ||
* @param {Function} callback - function (error, port) { ... } | ||
* - {Object|null} error - Any errors that occurred while port scanning. | ||
* - {String} status - 'open' if the port is in use. | ||
* 'closed' if the port is available. | ||
* @param {Number} port - Port to check status on. | ||
* @param {String|Object} options - host or options | ||
* - {String} host - Host of where to scan. Defaults to 'localhost'. | ||
* - {Object} options | ||
* - {String} host - Host of where to scan. Defaults to 'localhost'. | ||
* - {Number} timeout - Connection timeout. Defaults to 400ms. | ||
* @param {Function} callback - function (error, port) { ... } | ||
* - {Object|null} error - Any errors that occurred while port scanning. | ||
* - {String} status - 'open' if the port is in use. | ||
* 'closed' if the port is available. | ||
*/ | ||
portscanner.checkPortStatus = function(port, host, callback) { | ||
host = host || 'localhost' | ||
portscanner.checkPortStatus = function(port, options, callback) { | ||
if (typeof options === 'string') { | ||
// Assume this param is the host option | ||
options = {host: options} | ||
} | ||
var host = options.host || 'localhost' | ||
var timeout = options.timeout || 400 | ||
var socket = new Socket() | ||
, status = null | ||
, error = null | ||
@@ -68,5 +80,6 @@ // Socket connection established, port is open | ||
// If no response, assume port is not listening | ||
socket.setTimeout(400) | ||
socket.setTimeout(timeout) | ||
socket.on('timeout', function() { | ||
status = 'closed' | ||
error = new Error('Timeout (' + timeout + 'ms) occurred waiting for ' + host + ':' + port + ' to be available') | ||
socket.destroy() | ||
@@ -78,2 +91,3 @@ }) | ||
socket.on('error', function(exception) { | ||
error = exception | ||
status = 'closed' | ||
@@ -84,3 +98,4 @@ }) | ||
socket.on('close', function(exception) { | ||
callback(null, status) | ||
if (exception) error = exception | ||
callback(error, status) | ||
}) | ||
@@ -87,0 +102,0 @@ |
{ "name" : "portscanner" | ||
, "description" : "Asynchronous port scanner for Node.js" | ||
, "keywords" : [ "portscanner", "port", "scanner", "checker", "status" ] | ||
, "version" : "0.1.3" | ||
, "version" : "0.2.0" | ||
, "preferGlobal" : false | ||
, "homepage" : "https://github.com/baalexander/node-portscanner" | ||
, "author" : "Brandon Alexander <baalexander@gmail.com> (https://github.com/baalexander)" | ||
, "author" : [ | ||
"Brandon Alexander <baalexander@gmail.com> (https://github.com/baalexander)" | ||
, "Sean Massa <endangeredmassa@gmail.com> (http://massalabs.com)" | ||
] | ||
, "repository" : | ||
@@ -9,0 +12,0 @@ { "type" : "git" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10334
6
130
2
2