Server : nginx/1.18.0 System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/ecommerce/node_modules/default-gateway/ |
"use strict";
const execa = require("execa");
const ipRegex = require("ip-regex");
const gwArgs = "path Win32_NetworkAdapterConfiguration where IPEnabled=true get DefaultIPGateway,Index /format:table".split(" ");
const ifArgs = "path Win32_NetworkAdapter get Index,NetConnectionID /format:table".split(" ");
const parse = (gwTable, ifTable, family) => {
let gateway, gwid, result;
(gwTable || "").trim().split("\n").splice(1).some(line => {
const results = line.trim().split(/} +/) || [];
const gw = results[0];
const id = results[1];
gateway = (ipRegex[family]().exec((gw || "").trim()) || [])[0];
if (gateway) {
gwid = id;
return true;
}
});
(ifTable || "").trim().split("\n").splice(1).some(line => {
const i = line.indexOf(" ");
const id = line.substr(0, i).trim();
const name = line.substr(i + 1).trim();
if (id === gwid) {
result = {gateway, interface: name ? name : null};
return true;
}
});
if (!result) {
throw new Error("Unable to determine default gateway");
}
return result;
};
const spawnOpts = {
windowsHide: true,
};
const promise = family => {
return Promise.all([
execa.stdout("wmic", gwArgs, spawnOpts),
execa.stdout("wmic", ifArgs, spawnOpts),
]).then(results => {
const gwTable = results[0];
const ifTable = results[1];
return parse(gwTable, ifTable, family);
});
};
const sync = family => {
const gwTable = execa.sync("wmic", gwArgs, spawnOpts).stdout;
const ifTable = execa.sync("wmic", ifArgs, spawnOpts).stdout;
return parse(gwTable, ifTable, family);
};
module.exports.v4 = () => promise("v4");
module.exports.v6 = () => promise("v6");
module.exports.v4.sync = () => sync("v4");
module.exports.v6.sync = () => sync("v6");