Socket
Socket
Sign inDemoInstall

portscanner

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

portscanner - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

test.md

35

lib/portscanner.js

@@ -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"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc