Detalhes do pacote

address

node-modules39.4mMIT2.0.3

Get current machine IP, MAC and DNS servers.

address, ip, ipv4, mac

readme (leia-me)

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.

changelog (log de mudanças)

Changelog

2.0.3 (2024-06-19)

Bug Fixes

2.0.2 (2024-02-29)

Bug Fixes

  • should return scopeid = 0 address on IPv6 (#41) (6c98053)

2.0.0 (2023-09-22)

⚠ BREAKING CHANGES

  • Drop Node.js < 16 support

  • rename interface() to getInterfaceAddress()

Features

  • refactor with typescript to support cjs and esm both (#37) (8981f21)

1.2.2 (2022-12-17)

Bug Fixes


1.2.1 / 2022-09-13

fixes

others

1.2.0 / 2022-04-29

features

1.1.2 / 2019-08-26

fixes

1.1.1 / 2019-08-22

fixes

1.1.0 / 2019-04-24

features

1.0.3 / 2017-08-24

fixes

1.0.2 / 2017-05-26

  • fix: win32 get mac failed (#9)

1.0.1 / 2016-09-30

  • test: remove 0.12
  • fix: search interface before family match
  • add contributors

1.0.0 / 2015-08-06

  • chore: use npm scripts instead of Makefile
  • add benchmark

0.0.3 / 2013-11-04

  • get the first not local ip when interface not exists

0.0.2 / 2013-08-08

  • use networkInterface() to get mac fix #3

0.0.1 / 2013-07-31

  • ip(), ipv6(), mac(), dns() work on osx and linux now.
  • first commit