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 |
|
4 | Obtains 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 Unix (and macOS), the `netstat` command must be available.
|
8 | - On Windows, `wmic` must be available.
|
9 | - On IBM i, the `db2util` command must be available (provided by the `db2util` package).
|
10 |
|
11 | ## Usage
|
12 |
|
13 | ```js
|
14 | import {gateway4async, gateway4sync, gateway6async, gateway6sync} from "default-gateway";
|
15 |
|
16 | const {gateway, version, int} = await gateway4async();
|
17 | // gateway = '1.2.3.4', version = 4, int = 'en1'
|
18 |
|
19 | const {gateway, version, int} = await gateway6async();
|
20 | // gateway = '2001:db8::1', version = 6,int = 'en2'
|
21 |
|
22 | const {gateway, version, int} = gateway4sync();
|
23 | // gateway = '1.2.3.4', version = 4, int = 'en1'
|
24 |
|
25 | const {gateway, version, int} = gateway6sync();
|
26 | // gateway = '2001:db8::1', version = 6, int = 'en2'
|
27 | ```
|
28 |
|
29 | ## API
|
30 | ### gateway4async()
|
31 | ### gateway6async()
|
32 | ### gateway4sync()
|
33 | ### gateway6sync()
|
34 |
|
35 | Returns: `result` *Object*
|
36 | - `gateway` *String*: The IP address of the default gateway.
|
37 | - `version` *Number*: The IP address version of `gateway`.
|
38 | - `int` *String*: The name of the interface. On Windows, this is the network adapter name.
|
39 |
|
40 | The `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.
|
41 |
|
42 | ## License
|
43 |
|
44 | © [silverwind](https://github.com/silverwind), distributed under BSD licence
|