address
Get current machine IP, MAC and DNS servers.
Last updated 11 years ago by fengmk2 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install address 
SYNC missed versions from official npm registry.

address

NPM version Node.js CI Test coverage npm download

Get current machine IPv4, IPv6, MAC and DNS servers.

DNS servers receive from /etc/resolv.conf.

Install

npm install address

Usage

Get IP is sync and get MAC is async for now.

  • esm & typescript
import { ip, ipv6, mac } from 'address';

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

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

// vboxnet MAC
mac('vboxnet', function (err, addr) {
  console.log(addr); // '0a:00:27:00:00:00'
});
  • commonjs
const { ip, ipv6, mac } = require('address');

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

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

// vboxnet MAC
mac('vboxnet', function (err, addr) {
  console.log(addr); // '0a:00:27:00:00:00'
});

Get all addresses: IPv4, IPv6 and MAC

  • esm & typescript
import { address } from 'address';

address((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'
});

address('vboxnet', (err, addrs) => {
  console.log(addrs.ip, addrs.ipv6, addrs.mac);
  // '192.168.56.1', null, '0a:00:27:00:00:00'
});
  • commonjs
const { address } = require('address');

address((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'
});

address('vboxnet', (err, addrs) => {
  console.log(addrs.ip, addrs.ipv6, addrs.mac);
  // '192.168.56.1', null, '0a:00:27:00:00:00'
});

Get an interface info with family

  • esm & typescript
import { getInterfaceAddress } from 'address';

getInterfaceAddress('IPv4', 'eth1');
// { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }
  • commonjs
const { getInterfaceAddress } = require('address');

getInterfaceAddress('IPv4', 'eth1');
// { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }

Get DNS servers

  • esm & typescript
import { dns } from 'address';

dns((err, servers) => {
  console.log(servers);
  // ['10.13.2.1', '10.13.2.6']
});
  • commonjs
const { dns } = require('address');

dns((err, servers) => {
  console.log(servers);
  // ['10.13.2.1', '10.13.2.6']
});

Promise style apis

import { address, mac, dns } from 'address/promises';

const addr = await address();
const macAddress = await mac();
const servers = await dns();

License

MIT

Contributors


fengmk2


alsotang


jkelleyrtp


slyon


mariodu


mathieutu


zhangyuheng


semantic-release-bot


coolme200


whxaxes

This project follows the git-contributor spec, auto updated at Fri Sep 22 2023 20:49:32 GMT+0800.

Current Tags

  • 2.0.3                                ...           latest (5 months ago)
  • 1.2.2                                ...           release-1.x (2 years ago)

16 Versions

  • 2.0.3                                ...           5 months ago
  • 2.0.2                                ...           9 months ago
  • 2.0.1                                ...           a year ago
  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.3                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           9 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           11 years ago
Maintainers (1)
Downloads
Total 3
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)

© 2010 - cnpmjs.org x YWFE | Home | YWFE