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.3 to 1.0.4

node-portfinder.sublime-project

113

lib/portfinder.js

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

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

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

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

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

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

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

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

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

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

@@ -116,2 +115,11 @@ 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)) {

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

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

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

};
/**
* @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.3",
"version": "1.0.4",
"author": "Charlie Robbins <charlie.robbins@gmail.com>",

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

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

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

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

@@ -32,0 +33,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