Address

How many times have you checked for the IP, MAC and DNS servers on the CLI?

Well, you would have lost the count if you are into sever admin and maintaince, but either way it might be just to share some data over the LAN you would have checked for these, but when you need them programatically there a sweet module named address that will help you it's sweeter APIs.

Installing it: npm install address

Peep in:

1
2
3
4
5
6
7
> var address = require('address')

> address.MAC_RE
/(?:ether|HWaddr)\s+((?:[a-z0-9]{2}\:){5}[a-z0-9]{2})/i

> address.MAC_IP_RE
/inet\s(?:addr\:)?(\d+\.\d+\.\d+\.\d+)/

Example usage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var address = require('address');

// default interface 'eth' on linux, 'en' on osx.
address.ip();   // '192.168.0.2'
address.ipv6(); // 'fe80::7aca:39ff:feb0:e67d'
address.mac(function (err, addr) {
  console.log(addr); // '78:ca:39:b0:e6:7d'
});

// local loopback
address.ip('lo'); // '127.0.0.1'

address.dns(function (err, addrs) {
  console.log(addrs);
  // ['10.13.2.1', '10.13.2.6']
});

Get them all!

1
2
3
4
address(function (err, addrs) {
  console.log(addrs.ip, addrs.ipv6, addrs.mac);
  // '192.168.0.2', 'fe80::7aca:39ff:feb0:e67d', '78:ca:39:b0:e6:7d'
});

GIF FTW?!

address

Thanks to fengmk2 for helping us to find addresses in ease.

Suggest a module

Comments