web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.5 KiB

  1. address
  2. =======
  3. [![NPM version][npm-image]][npm-url]
  4. [![build status][travis-image]][travis-url]
  5. [![Test coverage][coveralls-image]][coveralls-url]
  6. [![Gittip][gittip-image]][gittip-url]
  7. [![David deps][david-image]][david-url]
  8. [![npm download][download-image]][download-url]
  9. [npm-image]: https://img.shields.io/npm/v/address.svg?style=flat-square
  10. [npm-url]: https://npmjs.org/package/address
  11. [travis-image]: https://img.shields.io/travis/node-modules/address.svg?style=flat-square
  12. [travis-url]: https://travis-ci.org/node-modules/address
  13. [coveralls-image]: https://img.shields.io/coveralls/node-modules/address.svg?style=flat-square
  14. [coveralls-url]: https://coveralls.io/r/node-modules/address?branch=master
  15. [gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat-square
  16. [gittip-url]: https://www.gittip.com/fengmk2/
  17. [david-image]: https://img.shields.io/david/node-modules/address.svg?style=flat-square
  18. [david-url]: https://david-dm.org/node-modules/address
  19. [download-image]: https://img.shields.io/npm/dm/address.svg?style=flat-square
  20. [download-url]: https://npmjs.org/package/address
  21. Get current machine IP, MAC and DNS servers.
  22. DNS servers receive from `/etc/resolv.conf`.
  23. ## Install
  24. ```bash
  25. $ npm install address
  26. ```
  27. ## Usage
  28. Get IP is sync and get MAC is async for now.
  29. ```js
  30. var address = require('address');
  31. // default interface 'eth' on linux, 'en' on osx.
  32. address.ip(); // '192.168.0.2'
  33. address.ipv6(); // 'fe80::7aca:39ff:feb0:e67d'
  34. address.mac(function (err, addr) {
  35. console.log(addr); // '78:ca:39:b0:e6:7d'
  36. });
  37. // local loopback
  38. address.ip('lo'); // '127.0.0.1'
  39. // vboxnet MAC
  40. address.mac('vboxnet', function (err, addr) {
  41. console.log(addr); // '0a:00:27:00:00:00'
  42. });
  43. ```
  44. ### Get all addresses: IPv4, IPv6 and MAC
  45. ```js
  46. address(function (err, addrs) {
  47. console.log(addrs.ip, addrs.ipv6, addrs.mac);
  48. // '192.168.0.2', 'fe80::7aca:39ff:feb0:e67d', '78:ca:39:b0:e6:7d'
  49. });
  50. address('vboxnet', function (err, addrs) {
  51. console.log(addrs.ip, addrs.ipv6, addrs.mac);
  52. // '192.168.56.1', null, '0a:00:27:00:00:00'
  53. });
  54. ```
  55. ### Get an interface info with family
  56. ```js
  57. address.interface('IPv4', 'eth1');
  58. // { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }
  59. ```
  60. ### Get DNS servers
  61. ```js
  62. address.dns(function (err, addrs) {
  63. console.log(addrs);
  64. // ['10.13.2.1', '10.13.2.6']
  65. });
  66. ```
  67. ## benchmark
  68. run `$ npm run benchmark`
  69. ```
  70. 18,929 op/s » #ip
  71. 17,622 op/s » #ipv6
  72. 16,347 op/s » #mac
  73. 11,906 op/s » #dns
  74. ```
  75. ## License
  76. [MIT](LICENSE.txt)