network
network copied to clipboard
Get Default Gateway macOS
On macOS the get default gateway script dose not work.
network.get_gateway_ip(function(err, ip) {
console.log(err || ip); // err may be 'No active network interface found.'
})
This is because the command ipconfig getoption en0 router
dose not work on macOS
Here is the error:
Error: Command failed: ipconfig getoption en0 router
at ChildProcess.exithandler (child_process.js:308:12)
at ChildProcess.emit (events.js:314:20)
at maybeClose (internal/child_process.js:1047:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) {
killed: false,
code: 1,
signal: null,
cmd: 'ipconfig getoption en0 router'
}