silverwind/default-gateway


Get the default network gateway, cross-platform.

License: BSD-2-Clause

Language: JavaScript

Keywords: aix, android, cross-platform, freebsd, gateway, ibmi, linux, macos, module, nodejs, openbsd, solaris, windows


default-gateway

Get the default network gateway, cross-platform.

Obtains the machine's default gateway through exec calls to OS routing interfaces. On Linux and Android, the ip command must be available (usually provided by the iproute2 package). On IBM i, the db2util command must be available (provided by the db2util package).

Installation

$ npm install default-gateway

Example

const defaultGateway = require('default-gateway');

defaultGateway.v4().then(result => {
  // result = {gateway: '1.2.3.4', interface: 'en1'}
});

defaultGateway.v6().then(result => {
  // result = {gateway: '2001:db8::1', interface: 'en2'}
});

const result = defaultGateway.v4.sync();
// result = {gateway: '1.2.3.4', interface: 'en1'}

const result = defaultGateway.v6.sync();
// result = {gateway: '2001:db8::1', interface: 'en2'}

API

defaultGateway.v4()

defaultGateway.v6()

defaultGateway.v4.sync()

defaultGateway.v6.sync()

Returns: result Object

  • gateway: The IP address of the default gateway.
  • interface: The name of the interface. On Windows, this is the network adapter name.

The .v{4,6}() methods return a Promise while the .v{4,6}.sync() variants will return the result synchronously.

The gateway property will always be defined on success, while interface can be null if it cannot be determined. All methods reject/throw on unexpected conditions.

License

© silverwind, distributed under BSD licence

Project Statistics

Sourcerank 14
Repository Size 176 KB
Stars 42
Forks 11
Watchers 1
Open issues 2
Dependencies 5
Contributors 8
Tags 51
Created
Last updated
Last pushed

Top Contributors See all

silverwind ThePrez patrickhrastnik  wu peng Sindre Sorhus eycorsican Andrew Powell karli-sjoberg

Packages Referencing this Repo

default-gateway
Get the default network gateway, cross-platform.
Latest release 5.0.3 - Updated - 42 stars

Recent Tags See all

5.0.3 August 14, 2019
5.0.2 June 14, 2019
5.0.1 June 14, 2019
5.0.0 June 14, 2019
4.2.0 March 06, 2019
v4.1.2 February 25, 2019
v4.1.1 February 25, 2019
v4.1.0 February 25, 2019
v4.0.1 February 23, 2019
v4.0.0 February 22, 2019
v3.1.0 February 15, 2019
v3.0.1 September 05, 2018
v3.0.0 August 23, 2018
v2.7.2 May 31, 2018
v2.7.1 March 27, 2018

Interesting Forks See all

sindresorhus/default-gateway
Get the default network gateway, cross-platform.
JavaScript - Last pushed - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-08-14 06:27:43 UTC

Login to resync this repository