Wrap ifconfig and parse result to json format (work on linux, not work on mac).
NOTE: This library only works with ifconfig
's older output format (prior to Ubuntu 18.04), containing the string "Link" with each interface. User keylase made a fork of this project called ipaddr-linux
that parses ip -s addr
, which has a more stable, predictable output. It works on Ubuntu 18.04 and newer, and provides an identical API.
root@ubuntu-2gb-sfo1-01:~# ifconfig-linux
{ eth0:
{ device: 'eth0',
link: { encap: 'Ethernet', hwaddr: '04:01:d3:db:fd:01' },
inet:
{ addr: '107.170.222.198',
bcast: '107.170.223.255',
mask: '255.255.240.0' },
inet6: { addr: 'fe80::601:d3ff:fedb:fd01/64', scope: 'Link' },
other:
{ collisions: 0,
txqueuelen: 1000,
rxBytes: 17278968,
txBytes: 19145675 },
rx: { packets: 71118, errors: 0, dropped: 0, overruns: 0, frame: 0 },
tx: { packets: 69479, errors: 0, dropped: 0, overruns: 0, carrier: 0 } },
lo:
{ device: 'lo',
link: { encap: 'Local' },
inet: { addr: '127.0.0.1', mask: '255.0.0.0' },
inet6: { addr: '::1/128', scope: 'Host' },
other:
{ collisions: 0,
txqueuelen: 0,
rxBytes: 30545056,
txBytes: 30545056 },
rx: { packets: 170494, errors: 0, dropped: 0, overruns: 0, frame: 0 },
tx: { packets: 170494, errors: 0, dropped: 0, overruns: 0, carrier: 0 } } }
In addition to ifconfig-linux shell command-line, you can also require('ifconfig-linux')
from your node.js application as you wish.
var promise = require('ifconfig-linux')(); // this return a promise
promise.then(console.dir);
This module is based on ifconfig
linux command. It's tested and works on Ubuntu 14.04.4
With npm do:
npm install ifconfig-linux -g
MIT