1. default-gateway
Get the default network gateway, cross-platform.
default-gateway
Package: default-gateway
Created by: silverwind
Last modified: Sat, 10 Jun 2023 12:16:02 GMT
Version: 7.2.2
License: BSD-2-Clause
Downloads: 49,289,186
Repository: https://github.com/silverwind/default-gateway

Install

npm install default-gateway
yarn add default-gateway

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

 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, distributed under BSD licence

Dependencies

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin