Socket
Socket
Sign inDemoInstall

default-gateway

Package Overview
Dependencies
20
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.2 to 5.0.3

11

android.js

@@ -29,11 +29,10 @@ "use strict";

const promise = family => {
return execa.stdout("ip", args[family]).then(stdout => {
return parse(stdout);
});
const promise = async family => {
const {stdout} = await execa("ip", args[family]);
return parse(stdout, family);
};
const sync = family => {
const result = execa.sync("ip", args[family]);
return parse(result.stdout);
const {stdout} = execa.sync("ip", args[family]);
return parse(stdout);
};

@@ -40,0 +39,0 @@

@@ -33,11 +33,10 @@ "use strict";

const promise = family => {
return execa.stdout("netstat", args[family]).then(stdout => {
return parse(stdout, family);
});
const promise = async family => {
const {stdout} = await execa("netstat", args[family]);
return parse(stdout, family);
};
const sync = family => {
const result = execa.sync("netstat", args[family]);
return parse(result.stdout, family);
const {stdout} = execa.sync("netstat", args[family]);
return parse(stdout, family);
};

@@ -44,0 +43,0 @@

@@ -30,11 +30,10 @@ "use strict";

const promise = family => {
return execa.stdout("netstat", args[family]).then(stdout => {
return parse(stdout);
});
const promise = async family => {
const {stdout} = await execa("netstat", args[family]);
return parse(stdout);
};
const sync = family => {
const result = execa.sync("netstat", args[family]);
return parse(result.stdout);
const {stdout} = execa.sync("netstat", args[family]);
return parse(stdout);
};

@@ -41,0 +40,0 @@

@@ -22,4 +22,5 @@ "use strict";

const promise = family => {
return execa.stdout(db2util, [sql, "-p", family, "-o", "json"]).then(stdout => parse(stdout));
const promise = async family => {
const {stdout} = await execa(db2util, [sql, "-p", family, "-o", "json"]);
return parse(stdout);
};

@@ -26,0 +27,0 @@

@@ -43,11 +43,10 @@ "use strict";

const promise = family => {
return execa.stdout("ip", args[family]).then(stdout => {
return parse(stdout, family);
});
const promise = async family => {
const {stdout} = await execa("ip", args[family]);
return parse(stdout, family);
};
const sync = family => {
const result = execa.sync("ip", args[family]);
return parse(result.stdout, family);
const {stdout} = execa.sync("ip", args[family]);
return parse(stdout, family);
};

@@ -54,0 +53,0 @@

@@ -33,11 +33,10 @@ "use strict";

const promise = family => {
return execa.stdout("netstat", args[family]).then(stdout => {
return parse(stdout);
});
const promise = async family => {
const {stdout} = await execa("netstat", args[family]);
return parse(stdout);
};
const sync = family => {
const result = execa.sync("netstat", args[family]);
return parse(result.stdout);
const {stdout} = execa.sync("netstat", args[family]);
return parse(stdout);
};

@@ -44,0 +43,0 @@

{
"name": "default-gateway",
"version": "5.0.2",
"version": "5.0.3",
"description": "Get the default network gateway, cross-platform.",

@@ -15,10 +15,9 @@ "author": "silverwind <me@silverwind.io>",

"dependencies": {
"execa": "^1.0.0",
"ip-regex": "^2.1.0"
"execa": "^2.0.3"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-config-silverwind": "^3.0.3",
"updates": "^8.1.0",
"ver": "5.0.1"
"eslint": "^6.1.0",
"eslint-config-silverwind": "^4.0.3",
"updates": "^8.5.1",
"ver": "5.1.2"
},

@@ -25,0 +24,0 @@ "files": [

@@ -33,11 +33,10 @@ "use strict";

const promise = family => {
return execa.stdout("netstat", args[family]).then(stdout => {
return parse(stdout);
});
const promise = async family => {
const {stdout} = await execa("netstat", args[family]);
return parse(stdout);
};
const sync = family => {
const result = execa.sync("netstat", args[family]);
return parse(result.stdout);
const {stdout} = execa.sync("netstat", args[family]);
return parse(stdout);
};

@@ -44,0 +43,0 @@

"use strict";
const execa = require("execa");
const ipRegex = require("ip-regex");
const os = require("os");
const net = require("net");
const gwArgs = "path Win32_NetworkAdapterConfiguration where IPEnabled=true get DefaultIPGateway,Index /format:table".split(" ");
const gwArgs = "path Win32_NetworkAdapterConfiguration where IPEnabled=true get DefaultIPGateway,GatewayCostMetric,IPConnectionMetric,Index /format:table".split(" ");
const ifArgs = index => `path Win32_NetworkAdapter where Index=${index} get NetConnectionID,MACAddress /format:table`.split(" ");

@@ -14,8 +14,29 @@

// Parsing tables like this. The final metric is GatewayCostMetric + IPConnectionMetric
//
// DefaultIPGateway GatewayCostMetric Index IPConnectionMetric
// {"1.2.3.4", "2001:db8::1"} {0, 256} 12 25
// {"2.3.4.5"} {25} 12 55
function parseGwTable(gwTable, family) {
for (const line of (gwTable || "").trim().split("\n").splice(1)) {
const [gw, id] = line.trim().split(/} +/) || [];
const gateway = (ipRegex[family]().exec((gw || "").trim()) || [])[0];
if (gateway) return [gateway, id];
let [bestGw, bestMetric, bestId] = [null, null, null];
for (let line of (gwTable || "").trim().split(/\r?\n/).splice(1)) {
line = line.trim();
const [_, gwArr, gwCostsArr, id, ipMetric] = /({.+?}) +?({.+?}) +?([0-9]+) +?([0-9]+)/g.exec(line) || [];
if (!gwArr) continue;
const gateways = (gwArr.match(/"(.+?)"/g) || []).map(match => match.substring(1, match.length - 1));
const gatewayCosts = (gwCostsArr.match(/[0-9]+/g) || []);
for (const [index, gateway] of Object.entries(gateways)) {
if (!gateway || `v${net.isIP(gateway)}` !== family) continue;
const metric = parseInt(gatewayCosts[index]) + parseInt(ipMetric);
if (!bestGw || metric < bestMetric) {
[bestGw, bestMetric, bestId] = [gateway, metric, id];
}
}
}
if (bestGw) return [bestGw, bestId];
}

@@ -33,3 +54,3 @@

for (const addr of addrs) {
if (addr && addr.mac === mac) {
if (addr && addr.mac && addr.mac.toLowerCase() === mac) {
return osname;

@@ -43,4 +64,4 @@ }

const promise = async family => {
const gwTable = await execa.stdout("wmic", gwArgs, spawnOpts);
const [gateway, id] = parseGwTable(gwTable, family) || [];
const {stdout} = await execa("wmic", gwArgs, spawnOpts);
const [gateway, id] = parseGwTable(stdout, family) || [];

@@ -53,4 +74,4 @@ if (!gateway) {

if (id) {
const ifTable = await execa.stdout("wmic", ifArgs(id), spawnOpts);
name = parseIfTable(ifTable);
const {stdout} = await execa("wmic", ifArgs(id), spawnOpts);
name = parseIfTable(stdout);
}

@@ -62,4 +83,4 @@

const sync = family => {
const gwTable = execa.sync("wmic", gwArgs, spawnOpts).stdout;
const [gateway, id] = parseGwTable(gwTable, family) || [];
const {stdout} = execa.sync("wmic", gwArgs, spawnOpts);
const [gateway, id] = parseGwTable(stdout, family) || [];

@@ -72,4 +93,4 @@ if (!gateway) {

if (id) {
const ifTable = execa.sync("wmic", ifArgs(id), spawnOpts).stdout;
name = parseIfTable(ifTable);
const {stdout} = execa.sync("wmic", ifArgs(id), spawnOpts);
name = parseIfTable(stdout);
}

@@ -76,0 +97,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc