Skip to content

Commit

Permalink
Merge pull request #14 from baalexander/localhost-127.0.0.1
Browse files Browse the repository at this point in the history
switch out localhost for 127.0.0.1
  • Loading branch information
EndangeredMassa committed Feb 5, 2014
2 parents 4407d6f + 0b72b83 commit 87f35e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
```
Expand Down
10 changes: 5 additions & 5 deletions example/portscan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions lib/portscanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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()
Expand Down

0 comments on commit 87f35e5

Please sign in to comment.