default-gateway
Advanced tools
Comparing version 2.2.1 to 2.2.2
@@ -16,3 +16,5 @@ "use strict"; | ||
(stdout || "").trim().split("\n").some(line => { | ||
const [_, gateway, iface] = /default via (.+?) dev (.+?)( |$)/.exec(line) || []; | ||
const results = /default via (.+?) dev (.+?)( |$)/.exec(line); | ||
const gateway = results[1]; | ||
const iface = results[2]; | ||
if (gateway && net.isIP(gateway)) { | ||
@@ -19,0 +21,0 @@ result = {gateway: gateway, interface: (iface ? iface : null)}; |
@@ -17,9 +17,7 @@ "use strict"; | ||
(stdout || "").trim().split("\n").some(line => { | ||
let target, gateway, _flags, _ref, _use, iface; | ||
if (family === "v4") { | ||
[target, gateway, _flags, _ref, _use, iface] = line.split(/ +/) || []; | ||
} else { | ||
[target, gateway, _flags, iface] = line.split(/ +/) || []; | ||
} | ||
if (dests.includes(target) && gateway && net.isIP(gateway)) { | ||
const results = line.split(/ +/) || []; | ||
const target = results[0]; | ||
const gateway = results[1]; | ||
const iface = results[family === "v4" ? 5 : 3]; | ||
if (dests.indexOf(target) !== -1 && gateway && net.isIP(gateway)) { | ||
result = {gateway: gateway, interface: (iface ? iface : null)}; | ||
@@ -26,0 +24,0 @@ return true; |
@@ -17,4 +17,7 @@ "use strict"; | ||
(stdout || "").trim().split("\n").some(line => { | ||
const [target, gateway, _flags, iface] = line.split(/ +/) || []; | ||
if (dests.includes(target) && gateway && net.isIP(gateway)) { | ||
const results = line.split(/ +/) || []; | ||
const target = results[0]; | ||
const gateway = results[1]; | ||
const iface = results[3]; | ||
if (dests.indexOf(target) !== -1 && gateway && net.isIP(gateway)) { | ||
result = {gateway: gateway, interface: (iface ? iface : null)}; | ||
@@ -21,0 +24,0 @@ return true; |
@@ -5,3 +5,3 @@ "use strict"; | ||
if (["android", "darwin", "freebsd", "linux", "win32"].includes(platform)) { | ||
if (["android", "darwin", "freebsd", "linux", "win32"].indexOf(platform) !== -1) { | ||
module.exports.v4 = () => require(`./${platform}`).v4(); | ||
@@ -8,0 +8,0 @@ module.exports.v6 = () => require(`./${platform}`).v6(); |
@@ -16,3 +16,5 @@ "use strict"; | ||
(stdout || "").trim().split("\n").some(line => { | ||
const [_, gateway, iface] = /default via (.+?) dev (.+?)( |$)/.exec(line) || []; | ||
const results = /default via (.+?) dev (.+?)( |$)/.exec(line); | ||
const gateway = results[1]; | ||
const iface = results[2]; | ||
if (gateway && net.isIP(gateway)) { | ||
@@ -19,0 +21,0 @@ result = {gateway: gateway, interface: (iface ? iface : null)}; |
{ | ||
"name": "default-gateway", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Get the default network gateway, cross-platform.", | ||
@@ -12,3 +12,3 @@ "author": "silverwind <me@silverwind.io>", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=4" | ||
}, | ||
@@ -15,0 +15,0 @@ "dependencies": { |
@@ -16,6 +16,9 @@ "use strict"; | ||
]).then(results => { | ||
const [gwTable, ifTable] = results; | ||
const gwTable = results[0]; | ||
const ifTable = results[1]; | ||
(gwTable || "").trim().split("\n").splice(1).some(line => { | ||
const [gw, id] = line.trim().split(/} +/); | ||
const results = line.trim().split(/} +/); | ||
const gw = results[0]; | ||
const id = results[1]; | ||
gateway = (ipRegex[family]().exec((gw || "").trim()) || [])[0]; | ||
@@ -22,0 +25,0 @@ if (gateway) { |
8798
161