diff --git a/README.md b/README.md index f05a481..0095419 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,20 @@ A brief example: var portscanner = require('portscanner') // Checks the status of a single port -portscanner.checkPortStatus(3000, 'localhost', function(error, status) { +portscanner.checkPortStatus(3000, '127.0.0.1', function(error, status) { // Status is 'open' if currently in use or 'closed' if available console.log(status) }) // Find the first available port. Asynchronously checks, so first port // determined as available is returned. -portscanner.findAPortNotInUse(3000, 3010, 'localhost', function(error, port) { +portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', function(error, port) { console.log('AVAILABLE PORT AT: ' + port) }) // Find the first port in use or blocked. Asynchronously checks, so first port // to respond is returned. -portscanner.findAPortInUse(3000, 3010, 'localhost', function(error, port) { +portscanner.findAPortInUse(3000, 3010, '127.0.0.1', function(error, port) { console.log('PORT IN USE AT: ' + port) }) ``` diff --git a/example/portscan.js b/example/portscan.js index b04f08a..1ab560d 100644 --- a/example/portscan.js +++ b/example/portscan.js @@ -5,27 +5,27 @@ var http = require('http') var server = http.createServer(function (request, response) { }) -server.listen(3005, 'localhost', function() { +server.listen(3005, '127.0.0.1', function() { // Checks the status of an individual port. - portscanner.checkPortStatus(3005, 'localhost', function(error, status) { + portscanner.checkPortStatus(3005, '127.0.0.1', function(error, status) { // Status should be 'open' since the HTTP server is listening on that port console.log('Status at port 3005 is ' + status) }) - portscanner.checkPortStatus(3000, 'localhost', function(error, status) { + portscanner.checkPortStatus(3000, '127.0.0.1', function(error, status) { // Status should be 'closed' since no service is listening on that port. console.log('Status at port 3000 is ' + status) }) // Finds a port that a service is listening on - portscanner.findAPortInUse(3000, 3010, 'localhost', function(error, port) { + portscanner.findAPortInUse(3000, 3010, '127.0.0.1', function(error, port) { // Port should be 3005 as the HTTP server is listening on that port console.log('Found an open port at ' + port) }) // Finds a port no service is listening on - portscanner.findAPortNotInUse(3000, 3010, 'localhost', function(error, port) { + portscanner.findAPortNotInUse(3000, 3010, '127.0.0.1', function(error, port) { // Will return any number between 3000 and 3010 (inclusive), that's not 3005. // The order is unknown as the port status checks are asynchronous. console.log('Found a closed port at ' + port) diff --git a/lib/portscanner.js b/lib/portscanner.js index fab9f13..db5aa5c 100644 --- a/lib/portscanner.js +++ b/lib/portscanner.js @@ -11,7 +11,7 @@ var portscanner = exports * @param {Number} startPort - Port to begin status check on (inclusive). * @param {Number} endPort - Last port to check status on (inclusive). * Defaults to 65535. - * @param {String} host - Where to scan. Defaults to 'localhost'. + * @param {String} host - Where to scan. Defaults to '127.0.0.1'. * @param {Function} callback - function (error, port) { ... } * - {Object|null} error - Any errors that occurred while port scanning. * - {Number|Boolean} port - The first open port found. Note, this is the @@ -30,7 +30,7 @@ portscanner.findAPortInUse = function(startPort, endPort, host, callback) { * @param {Number} startPort - Port to begin status check on (inclusive). * @param {Number} endPort - Last port to check status on (inclusive). * Defaults to 65535. - * @param {String} host - Where to scan. Defaults to 'localhost'. + * @param {String} host - Where to scan. Defaults to '127.0.0.1'. * @param {Function} callback - function (error, port) { ... } * - {Object|null} error - Any errors that occurred while port scanning. * - {Number|Boolean} port - The first closed port found. Note, this is the @@ -47,9 +47,9 @@ portscanner.findAPortNotInUse = function(startPort, endPort, host, callback) { * * @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'. + * - {String} host - Host of where to scan. Defaults to '127.0.0.1'. * - {Object} options - * - {String} host - Host of where to scan. Defaults to 'localhost'. + * - {String} host - Host of where to scan. Defaults to '127.0.0.1'. * - {Number} timeout - Connection timeout. Defaults to 400ms. * @param {Function} callback - function (error, port) { ... } * - {Object|null} error - Any errors that occurred while port scanning. @@ -62,7 +62,7 @@ portscanner.checkPortStatus = function(port, options, callback) { options = {host: options} } - var host = options.host || 'localhost' + var host = options.host || '127.0.0.1' var timeout = options.timeout || 400 var socket = new Socket()