default-gateway
Get the default network gateway, cross-platform.
Obtains the network gateway through exec
calls to OS routing interfaces. Supports Linux, macOS and Windows. On Linux, the ip
command must be available (usually provided by the iproute2
package).
Installation
$ npm install --save default-gateway
Example
const defaultGateway = require('default-gateway');
defaultGateway.v4().then(result => {
});
defaultGateway.v6().then(result => {
});
API
default-gateway.v4()
Returns a promise that resolves to a object containing the IPv4 gateway
and interface
. If it succeeds, gateway
will always be defined, while interface
can be absent. Rejects when the gateway cannot be determined.
default-gateway.v6()
Returns a promise that resolves to a object containing the IPv6 gateway
and interface
. If it succeeds, gateway
will always be defined, while interface
can be absent. Rejects when the gateway cannot be determined.
© silverwind, distributed under BSD licence