You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8 KiB

5 years ago
  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://api.travis-ci.org/silverwind/default-gateway.svg?style=flat)](https://travis-ci.org/silverwind/default-gateway)
  3. > Get the default network gateway, cross-platform.
  4. 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).
  5. ## Installation
  6. ```
  7. $ npm install default-gateway
  8. ```
  9. ## Example
  10. ```js
  11. const defaultGateway = require('default-gateway');
  12. defaultGateway.v4().then(result => {
  13. // result = {gateway: '1.2.3.4', interface: 'en1'}
  14. });
  15. defaultGateway.v6().then(result => {
  16. // result = {gateway: '2001:db8::1', interface: 'en2'}
  17. });
  18. const result = defaultGateway.v4.sync();
  19. // result = {gateway: '1.2.3.4', interface: 'en1'}
  20. const result = defaultGateway.v6.sync();
  21. // result = {gateway: '2001:db8::1', interface: 'en2'}
  22. ```
  23. ## API
  24. ### defaultGateway.v4()
  25. ### defaultGateway.v6()
  26. ### defaultGateway.v4.sync()
  27. ### defaultGateway.v6.sync()
  28. Returns: `result` *Object*
  29. - `gateway`: The IP address of the default gateway.
  30. - `interface`: The name of the interface. On Windows, this is the network adapter name.
  31. The `.v{4,6}()` methods return a Promise while the `.v{4,6}.sync()` variants will return the result synchronously.
  32. 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.
  33. ## License
  34. © [silverwind](https://github.com/silverwind), distributed under BSD licence