# default-gateway

> Get the default network gateway, cross-platform.

Latest version **7.2.2** (published 2023-06-10) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install default-gateway
pnpm add default-gateway
yarn add default-gateway
bun add default-gateway
```

## Health

**Score 33/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 7.2.2 |
| Published | 2023-06-10 |
| First published | 2017-06-08 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | separate (@types/default-gateway) |
| Module format | ESM |
| Node | >= 16 |
| Dependencies | 1 |
| Unpacked size | 12 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 90 |
| Author | silverwind |
| Maintainers | silverwind |

## Links

- npm: https://www.npmjs.com/package/default-gateway
- Repository: https://github.com/silverwind/default-gateway
- Homepage: https://github.com/silverwind/default-gateway#readme
- Issues: https://github.com/silverwind/default-gateway/issues
- npm.io page: https://npm.io/package/default-gateway

## Dependencies (1)

- [execa](https://npm.io/package/execa.md) ^7.1.1

## Recent versions

- 7.2.2 (latest) — 2023-06-10
- 7.2.1 — 2023-06-10
- 7.2.0 — 2023-06-10
- 7.1.0 — 2023-06-10
- 7.0.0 — 2023-06-10
- 6.0.3 — 2021-01-11
- 6.0.2 — 2020-08-26
- 6.0.1 — 2020-05-25
- 6.0.0 — 2020-03-11
- 5.0.5 — 2019-11-14
- 5.0.4 — 2019-10-15
- 5.0.3 — 2019-08-14
- 5.0.2 — 2019-06-14
- 5.0.1 — 2019-06-14
- 5.0.0 — 2019-06-14
- … 39 more at https://npm.io/package/default-gateway/versions

## README

# default-gateway
[![](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)

Obtains the machine's default gateway through `exec` calls to OS routing ints.

- On Linux and Android, the `ip` command must be available (usually provided by the `iproute2` package).
- On Unix (and macOS), the `netstat` command must be available.
- On Windows, `wmic` must be available.
- On IBM i, the `db2util` command must be available (provided by the `db2util` package).

## Usage

```js
import {gateway4async, gateway4sync, gateway6async, gateway6sync} from "default-gateway";

const {gateway, version, int} = await gateway4async();
// gateway = '1.2.3.4', version = 4, int = 'en1'

const {gateway, version, int} = await gateway6async();
// gateway = '2001:db8::1', version = 6,int = 'en2'

const {gateway, version, int} = gateway4sync();
// gateway = '1.2.3.4', version = 4, int = 'en1'

const {gateway, version, int} = gateway6sync();
// gateway = '2001:db8::1', version = 6, int = 'en2'
```

## API
### gateway4async()
### gateway6async()
### gateway4sync()
### gateway6sync()

Returns: `result` *Object*
  - `gateway` *String*: The IP address of the default gateway.
  - `version` *Number*: The IP address version of `gateway`.
  - `int` *String*: The name of the interface. On Windows, this is the network adapter name.

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.

## License

© [silverwind](https://github.com/silverwind), distributed under BSD licence

---
_Source: https://npm.io/package/default-gateway · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
