Skip to content

Commit

Permalink
added options param to checkPortStatus; supports host and timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
EndangeredMassa committed Oct 14, 2013
1 parent b8acb18 commit 16d0db3
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lib/portscanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,26 @@ portscanner.findAPortNotInUse = function(startPort, endPort, host, callback) {
/**
* Checks the status of an individual port.
*
* @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
Expand All @@ -65,7 +76,6 @@ portscanner.checkPortStatus = function(port, host, callback) {
})

// If no response, assume port is not listening
timeout = 400
socket.setTimeout(timeout)
socket.on('timeout', function() {
status = 'closed'
Expand Down

0 comments on commit 16d0db3

Please sign in to comment.