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 Windows, wmic must be available.
  • On IBM i, the db2util command must be available (provided by the db2util package).
  • On Unix (and macOS), the netstat command must be available.

Installation

$ npm install default-gateway

Example

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

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

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

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

const {gateway, interface} = defaultGateway.v6.sync();
// 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 16
Repository Size 193 KB
Stars 47
Forks 11
Watchers 1
Open issues 2
Dependencies 5
Contributors 9
Tags 53
Created
Last updated
Last pushed

Top Contributors See all

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

Packages Referencing this Repo

default-gateway
Get the default network gateway, cross-platform.
Latest release 5.0.5 - Updated - 47 stars

Recent Tags See all

5.0.5 November 14, 2019
5.0.4 October 15, 2019
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

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-11-14 20:40:30 UTC

Login to resync this repository