Socket
Socket
Sign inDemoInstall

address

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    address

Get current machine IP, MAC and DNS servers.


Version published
Weekly downloads
11M
increased by3.55%
Maintainers
1
Install size
60.9 kB
Created
Weekly downloads
 

Package description

What is address?

The 'address' npm package is a utility for retrieving detailed information about the network interfaces of the host machine. It can be used to get IP addresses, MAC addresses, and DNS servers, among other things. This package is particularly useful for applications that need to be aware of the network configuration of the host they are running on.

What are address's main functionalities?

Get IP Address

This feature allows you to retrieve the IPv4 or IPv6 address of the host machine. It's useful for applications that need to know their own IP address, for instance, to communicate with other services in a network.

const address = require('address');

// Get the IPv4 address
address.ip(); // '192.168.0.2'

// Get the IPv6 address
address.ipv6(); // 'fe80::7ca0:ab22:703a:b329'

Get MAC Address

This feature enables you to get the MAC address of the host machine. This can be useful for applications that need to identify the network interface of the host.

const address = require('address');

// Get the MAC address
address.mac(function (err, addr) {
  console.log(addr); // '78:ca:39:b0:e6:7c'
});

Get DNS Servers

This feature provides the DNS servers configured on the host machine. It's useful for applications that need to perform DNS lookups or need to know about the network's DNS configuration.

const address = require('address');

// Get DNS servers
console.log(address.dns()); // ['8.8.8.8', '8.8.4.4']

Other packages similar to address

Readme

Source

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.

Keywords

FAQs

Last updated on 29 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc