租房小程序前端代码
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.

93 lines
3.4 KiB

3 months ago
  1. address
  2. =======
  3. [![NPM version][npm-image]][npm-url]
  4. [![Node.js CI](https://github.com/node-modules/address/actions/workflows/nodejs.yml/badge.svg)](https://github.com/node-modules/address/actions/workflows/nodejs.yml)
  5. [![Test coverage][coveralls-image]][coveralls-url]
  6. [![npm download][download-image]][download-url]
  7. [npm-image]: https://img.shields.io/npm/v/address.svg?style=flat-square
  8. [npm-url]: https://npmjs.org/package/address
  9. [coveralls-image]: https://img.shields.io/coveralls/node-modules/address.svg?style=flat-square
  10. [coveralls-url]: https://coveralls.io/r/node-modules/address?branch=master
  11. [download-image]: https://img.shields.io/npm/dm/address.svg?style=flat-square
  12. [download-url]: https://npmjs.org/package/address
  13. Get current machine IP, MAC and DNS servers.
  14. DNS servers receive from `/etc/resolv.conf`.
  15. ## Install
  16. ```bash
  17. $ npm install address
  18. ```
  19. ## Usage
  20. Get IP is sync and get MAC is async for now.
  21. ```js
  22. const address = require('address');
  23. // default interface 'eth' on linux, 'en' on osx.
  24. address.ip(); // '192.168.0.2'
  25. address.ipv6(); // 'fe80::7aca:39ff:feb0:e67d'
  26. address.mac(function (err, addr) {
  27. console.log(addr); // '78:ca:39:b0:e6:7d'
  28. });
  29. // local loopback
  30. address.ip('lo'); // '127.0.0.1'
  31. // vboxnet MAC
  32. address.mac('vboxnet', function (err, addr) {
  33. console.log(addr); // '0a:00:27:00:00:00'
  34. });
  35. ```
  36. ### Get all addresses: IPv4, IPv6 and MAC
  37. ```js
  38. address((err, addrs) => {
  39. console.log(addrs.ip, addrs.ipv6, addrs.mac);
  40. // '192.168.0.2', 'fe80::7aca:39ff:feb0:e67d', '78:ca:39:b0:e6:7d'
  41. });
  42. address('vboxnet', (err, addrs) => {
  43. console.log(addrs.ip, addrs.ipv6, addrs.mac);
  44. // '192.168.56.1', null, '0a:00:27:00:00:00'
  45. });
  46. ```
  47. ### Get an interface info with family
  48. ```js
  49. address.interface('IPv4', 'eth1');
  50. // { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }
  51. ```
  52. ### Get DNS servers
  53. ```js
  54. address.dns((err, addrs) => {
  55. console.log(addrs);
  56. // ['10.13.2.1', '10.13.2.6']
  57. });
  58. ```
  59. ## License
  60. [MIT](LICENSE.txt)
  61. <!-- GITCONTRIBUTOR_START -->
  62. ## Contributors
  63. |[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/1147375?v=4" width="100px;"/><br/><sub><b>alsotang</b></sub>](https://github.com/alsotang)<br/>|[<img src="https://avatars.githubusercontent.com/u/10237910?v=4" width="100px;"/><br/><sub><b>jkelleyrtp</b></sub>](https://github.com/jkelleyrtp)<br/>|[<img src="https://avatars.githubusercontent.com/u/1409643?v=4" width="100px;"/><br/><sub><b>mariodu</b></sub>](https://github.com/mariodu)<br/>|[<img src="https://avatars.githubusercontent.com/u/11351322?v=4" width="100px;"/><br/><sub><b>mathieutu</b></sub>](https://github.com/mathieutu)<br/>|[<img src="https://avatars.githubusercontent.com/u/2139038?v=4" width="100px;"/><br/><sub><b>zhangyuheng</b></sub>](https://github.com/zhangyuheng)<br/>|
  64. | :---: | :---: | :---: | :---: | :---: | :---: |
  65. [<img src="https://avatars.githubusercontent.com/u/1400114?v=4" width="100px;"/><br/><sub><b>coolme200</b></sub>](https://github.com/coolme200)<br/>|[<img src="https://avatars.githubusercontent.com/u/5856440?v=4" width="100px;"/><br/><sub><b>whxaxes</b></sub>](https://github.com/whxaxes)<br/>
  66. This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Sep 13 2022 09:09:11 GMT+0800`.
  67. <!-- GITCONTRIBUTOR_END -->