npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

default-network

v0.2.0

Published

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

Downloads

538

Readme

default-network

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-network

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 route = require('default-network');
route.collect(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 route = require('default-network');
route.collect(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

Author

Masayuki Higashino

License

The MIT License