UNPKG

1.67 kBMarkdownView Raw
1# default-gateway
2[![](https://img.shields.io/npm/v/default-gateway.svg?style=flat)](https://www.npmjs.org/package/default-gateway) [![](https://img.shields.io/npm/dm/default-gateway.svg)](https://www.npmjs.org/package/default-gateway) [![](https://packagephobia.com/badge?p=default-gateway)](https://packagephobia.com/result?p=default-gateway)
3
4Obtains the machine's default gateway through `exec` calls to OS routing ints.
5
6- On Linux and Android, the `ip` command must be available (usually provided by the `iproute2` package).
7- On Windows, `wmic` must be available.
8- On IBM i, the `db2util` command must be available (provided by the `db2util` package).
9- On Unix (and macOS), the `netstat` command must be available.
10
11## Usage
12
13```js
14import {gateway4async, gateway4sync, gateway6async, gateway6sync} from "default-gateway";
15
16const {gateway, int} = await gateway4async();
17// gateway = '1.2.3.4', int = 'en1'
18
19const {gateway, int} = await gateway6async();
20// gateway = '2001:db8::1', int = 'en2'
21
22const {gateway, int} = gateway4sync();
23// gateway = '1.2.3.4', int = 'en1'
24
25const {gateway, int} = gateway6sync();
26// gateway = '2001:db8::1', int = 'en2'
27```
28
29## API
30### gateway4async()
31### gateway6async()
32### gateway4sync()
33### gateway6sync()
34
35Returns: `result` *Object*
36 - `gateway`: The IP address of the default gateway.
37 - `int`: The name of the interface. On Windows, this is the network adapter name.
38
39The `gateway` property will always be defined on success, while `int` can be `null` if it cannot be determined. All methods reject/throw on unexpected conditions.
40
41## License
42
43© [silverwind](https://github.com/silverwind), distributed under BSD licence