Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

portfinder

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

portfinder - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

113

lib/portfinder.js

@@ -11,3 +11,2 @@ /*

var fs = require('fs'),
os = require('os'),
net = require('net'),

@@ -77,2 +76,4 @@ path = require('path'),

//
var defaultHosts = ['::1', '127.0.0.1', '0.0.0.0'];
exports.getPort = function (options, callback) {

@@ -87,4 +88,4 @@ if (!callback) {

var hasUserGivenHost;
for (var i = 0; i < exports._defaultHosts.length; i++) {
if (exports._defaultHosts[i] === options.host) {
for (var i = 0; i < defaultHosts.length; i++) {
if (defaultHosts[i] === options.host) {
hasUserGivenHost = true;

@@ -96,3 +97,3 @@ break;

if (!hasUserGivenHost) {
exports._defaultHosts.push(options.host);
defaultHosts.push(options.host);
}

@@ -103,3 +104,3 @@

var openPorts = [];
return async.eachSeries(exports._defaultHosts, function(host, next) {
return async.eachSeries(defaultHosts, function(host, next) {
return internals.testPort({ host: host, port: options.port }, function(err, port) {

@@ -115,11 +116,2 @@ if (err) {

if (err) {
// Handle MacOS 10.11.5+ interface changes and running portfinder from
// within the same netmask, including from within a locally running VM.
if (err.code === 'EADDRNOTAVAIL') {
var idx = exports._defaultHosts.indexOf(err.address);
exports._defaultHosts.splice(idx, 1);
}
// NOTE: net.isIPv6(err.address) check is likely === EADDRNOTAVAIL check above (+risk)
if (err.address && net.isIPv6(err.address)) {

@@ -134,3 +126,3 @@ if (options.host && net.isIPv6(options.host)) {

// filter our defaultHosts to only be ipv4, start over
exports._defaultHosts = exports._defaultHosts.filter(function(_host) {
defaultHosts = defaultHosts.filter(function(_host) {
return net.isIPv4(_host);

@@ -310,92 +302,1 @@ });

};
/**
* @desc List of internal hostnames provided by your machine. A user
* provided hostname may also be provided when calling portfinder.getPort,
* which would then be added to the default hosts we lookup and return here.
*
* @return {array}
*
* Long Form Explantion:
*
* - Input: (os.networkInterfaces() w/ MacOS 10.11.5+ and running a VM)
*
* { lo0:
* [ { address: '::1',
* netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
* family: 'IPv6',
* mac: '00:00:00:00:00:00',
* scopeid: 0,
* internal: true },
* { address: '127.0.0.1',
* netmask: '255.0.0.0',
* family: 'IPv4',
* mac: '00:00:00:00:00:00',
* internal: true },
* { address: 'fe80::1',
* netmask: 'ffff:ffff:ffff:ffff::',
* family: 'IPv6',
* mac: '00:00:00:00:00:00',
* scopeid: 1,
* internal: true } ],
* en0:
* [ { address: 'fe80::a299:9bff:fe17:766d',
* netmask: 'ffff:ffff:ffff:ffff::',
* family: 'IPv6',
* mac: 'a0:99:9b:17:76:6d',
* scopeid: 4,
* internal: false },
* { address: '10.0.1.22',
* netmask: '255.255.255.0',
* family: 'IPv4',
* mac: 'a0:99:9b:17:76:6d',
* internal: false } ],
* awdl0:
* [ { address: 'fe80::48a8:37ff:fe34:aaef',
* netmask: 'ffff:ffff:ffff:ffff::',
* family: 'IPv6',
* mac: '4a:a8:37:34:aa:ef',
* scopeid: 8,
* internal: false } ],
* vnic0:
* [ { address: '10.211.55.2',
* netmask: '255.255.255.0',
* family: 'IPv4',
* mac: '00:1c:42:00:00:08',
* internal: false } ],
* vnic1:
* [ { address: '10.37.129.2',
* netmask: '255.255.255.0',
* family: 'IPv4',
* mac: '00:1c:42:00:00:09',
* internal: false } ] }
*
* - Output:
*
* [
* '0.0.0.0',
* '::1',
* '127.0.0.1',
* '10.0.1.22',
* '10.211.55.2',
* '10.37.129.2'
* ]
*
* Note we export this so we can use it in our tests, otherwise this API is private
*/
exports._defaultHosts = (function() {
var interfaces = os.networkInterfaces(),
interfaceNames = Object.keys(interfaces),
hiddenButImportantHost = '0.0.0.0', // !important - dont remove, hence the naming :)
results = [hiddenButImportantHost];
for (var i = 0; i < interfaceNames.length; i++) {
var _interface = interfaces[interfaceNames[i]];
for (var j = 0; j < _interface.length; j++) {
var curr = _interface[j];
if (curr.internal || curr.netmask === '255.255.255.0') {
results.push(curr.address);
}
}
}
return results;
}());

2

package.json
{
"name": "portfinder",
"description": "A simple tool to find an open port on the current machine",
"version": "1.0.4",
"version": "1.0.5",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",

@@ -6,0 +6,0 @@ "repository": {

"use strict";
var async = require('async'),
http = require('http'),
portfinder = require('..');
http = require('http');

@@ -30,3 +29,3 @@

function (next) {
var hosts = [].concat(portfinder._defaultHosts);
var hosts = ['127.0.0.1', '0.0.0.0', '::1'];
while (hosts.length > 1) { servers.push(createServer(base, hosts.shift())); }

@@ -33,0 +32,0 @@ servers.push(createServer(base, hosts.shift(), next)); // call next for host

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