address

2018-11-10 admin

address是什么

什么是address,Get current machine IP, MAC and DNS servers.

address使用教程帮助文档

address

NPM version build status Test coverage Gittip David deps npm download

Get current machine IP, 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.

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'

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

Get all addresses: IPv4, IPv6 and MAC

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

address('vboxnet', function (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

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

Get DNS servers

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

benchmark

run $ npm run benchmark

18,929 op/s » #ip
17,622 op/s » #ipv6
16,347 op/s » #mac
11,906 op/s » #dns

License

MIT

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-45057.html

文章标题:address

相关文章
Is it possible to hide the address bar in iOS 7 Safari? [duplicate]
crowjonahDaimz提出了一个问题:Is it possible to hide the address bar in iOS 7 Safari? [duplicate],或许与您遇到的问题类似。 回答者valentinvieriu...
2018-04-27
Google Maps v3 API - Auto Complete (address)
Matt提出了一个问题:Google Maps v3 API - Auto Complete (address),或许与您遇到的问题类似。 回答者Matt给出了该问题的处理方式: Fixed. The autocomplete librar...
2018-04-13
Get the page file name from the address bar
DruzionBoardy提出了一个问题:Get the page file name from the address bar,或许与您遇到的问题类似。 回答者Juan Mendes给出了该问题的处理方式: https://develop...
2018-04-23
url-parse-as-address
url-parse-as-address是什么 什么是url-parse-as-address,Parse a url assuming http if no protocol or // is provided. url-parse-a...
2018-09-22
How to get client IP address using jQuery
hippietrailWondering提出了一个问题:How to get client IP address using jQuery,或许与您遇到的问题类似。 回答者samddCMS给出了该问题的处理方式: jQuery can ha...
2018-04-12
How to change browser address bar without reloading page - HTML/Javascript [duplicate]
CommunityRadiantHex提出了一个问题:How to change browser address bar without reloading page - HTML/Javascript [duplicate],或许与您遇到...
2018-04-13
server-address
server-address是什么 什么是server-address,Listen to a randomly available port and resolve urls relative to the server address ...
2018-10-26
回到顶部