Socket
Socket
Sign inDemoInstall

default-gateway

Package Overview
Dependencies
5
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    default-gateway

A Node.js module to get default gateway and default interface.


Version published
Maintainers
1
Install size
2.05 MB
Created

Package description

What is default-gateway?

The default-gateway npm package provides a simple and efficient way to find the default gateway of the local machine's network interfaces. It supports multiple operating systems, including Windows, macOS, and Linux, making it a versatile tool for network-related programming tasks. This package can be particularly useful for applications that need to interact with the network layer of the operating system, such as determining the best route for network traffic or configuring network settings programmatically.

What are default-gateway's main functionalities?

Finding the default gateway for IPv4

This feature allows you to asynchronously find the default IPv4 gateway of the local machine. The result is an object containing the gateway's IP address and the associated network interface.

const defaultGateway = require('default-gateway');
defaultGateway.v4().then(result => console.log(result));

Finding the default gateway for IPv6

Similar to the IPv4 feature, this allows for the asynchronous discovery of the default IPv6 gateway. The result includes the IPv6 gateway address and the network interface it is associated with.

const defaultGateway = require('default-gateway');
defaultGateway.v6().then(result => console.log(result));

Other packages similar to default-gateway

Readme

Source

default-gateway

A Node.js module to get default gateway and default interface.

100% Pure JavaScript😽

This module depends on following commands by using chid_process provided by Node.js.

  • win32
    • wmic path Win32_NetworkAdapterConfiguration get *
    • wmic path Win32_NetworkAdapter get *
  • darwin
    • netstat -rn -f inet
    • netstat -rn -f inet6
  • linux
    • netstat -rn -A inet
    • netstat -rn -A inet6

Installation

npm install default-gateway

API

collect(callback)

Asynchronously collects a object which contains interface names, families (IPv4 or IPv6), and addresses. The callback gets two arguments (error, data).

Example 1

How to get default gateway and default interface.

An example code: example1.js

var defaultGateway = require('default-gateway');
defaultGateway(function(error, data) {
  console.log(data);
});

An example output:

{ en4:
   [ { family: 'IPv4', address: '192.168.1.1' },
     { family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en4' } ],
  en0:
   [ { family: 'IPv4', address: '192.168.1.1' },
     { family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en0' } ],
  en8:
   [ { family: 'IPv4', address: '192.168.1.1' },
     { family: 'IPv6', address: 'fe80::20b:a2ff:fede:2886%en8' } ] }
Example 2

How to get default interface from os.networkInterfaces().

An example code: example2.js

var os = require('os');
var defaultGateway = require('default-gateway');
defaultGateway(function(error, data) {
  names = Object.keys(data);
  // names[0] is 'en4'
  console.log(os.networkInterfaces()[names[0]]);
});

An example output:

[ { address: 'fe80::6a5b:35ff:fe96:cc05',
    netmask: 'ffff:ffff:ffff:ffff::',
    family: 'IPv6',
    mac: '00:00:00:00:00:00',
    scopeid: 14,
    internal: false },
  { address: '2001:a0ae:7c22:0:6a5b:35ff:fe96:cc05',
    netmask: 'ffff:ffff:ffff:ffff::',
    family: 'IPv6',
    mac: '00:00:00:00:00:00',
    scopeid: 0,
    internal: false },
  { address: '2001:a0ae:7c22:0:a8d1:fef3:2917:cd87',
    netmask: 'ffff:ffff:ffff:ffff::',
    family: 'IPv6',
    mac: '00:00:00:00:00:00',
    scopeid: 0,
    internal: false },
  { address: '192.168.1.10',
    netmask: '255.255.255.0',
    family: 'IPv4',
    mac: '00:00:00:00:00:00',
    internal: false } ]

Development

Test

npm test

or

./node_modules/.bin/gulp test

or

./node_modules/.bin/mocha

License

The MIT License

Keywords

FAQs

Last updated on 08 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc