| [9af201e] | 1 | address
|
|---|
| 2 | =======
|
|---|
| 3 |
|
|---|
| 4 | [![NPM version][npm-image]][npm-url]
|
|---|
| 5 | [](https://github.com/node-modules/address/actions/workflows/nodejs.yml)
|
|---|
| 6 | [![Test coverage][coveralls-image]][coveralls-url]
|
|---|
| 7 | [![npm download][download-image]][download-url]
|
|---|
| 8 |
|
|---|
| 9 | [npm-image]: https://img.shields.io/npm/v/address.svg?style=flat-square
|
|---|
| 10 | [npm-url]: https://npmjs.org/package/address
|
|---|
| 11 | [coveralls-image]: https://img.shields.io/coveralls/node-modules/address.svg?style=flat-square
|
|---|
| 12 | [coveralls-url]: https://coveralls.io/r/node-modules/address?branch=master
|
|---|
| 13 | [download-image]: https://img.shields.io/npm/dm/address.svg?style=flat-square
|
|---|
| 14 | [download-url]: https://npmjs.org/package/address
|
|---|
| 15 |
|
|---|
| 16 | Get current machine IP, MAC and DNS servers.
|
|---|
| 17 |
|
|---|
| 18 | DNS servers receive from `/etc/resolv.conf`.
|
|---|
| 19 |
|
|---|
| 20 | ## Install
|
|---|
| 21 |
|
|---|
| 22 | ```bash
|
|---|
| 23 | $ npm install address
|
|---|
| 24 | ```
|
|---|
| 25 |
|
|---|
| 26 | ## Usage
|
|---|
| 27 |
|
|---|
| 28 | Get IP is sync and get MAC is async for now.
|
|---|
| 29 |
|
|---|
| 30 | ```js
|
|---|
| 31 | const address = require('address');
|
|---|
| 32 |
|
|---|
| 33 | // default interface 'eth' on linux, 'en' on osx.
|
|---|
| 34 | address.ip(); // '192.168.0.2'
|
|---|
| 35 | address.ipv6(); // 'fe80::7aca:39ff:feb0:e67d'
|
|---|
| 36 | address.mac(function (err, addr) {
|
|---|
| 37 | console.log(addr); // '78:ca:39:b0:e6:7d'
|
|---|
| 38 | });
|
|---|
| 39 |
|
|---|
| 40 | // local loopback
|
|---|
| 41 | address.ip('lo'); // '127.0.0.1'
|
|---|
| 42 |
|
|---|
| 43 | // vboxnet MAC
|
|---|
| 44 | address.mac('vboxnet', function (err, addr) {
|
|---|
| 45 | console.log(addr); // '0a:00:27:00:00:00'
|
|---|
| 46 | });
|
|---|
| 47 | ```
|
|---|
| 48 |
|
|---|
| 49 | ### Get all addresses: IPv4, IPv6 and MAC
|
|---|
| 50 |
|
|---|
| 51 | ```js
|
|---|
| 52 | address((err, addrs) => {
|
|---|
| 53 | console.log(addrs.ip, addrs.ipv6, addrs.mac);
|
|---|
| 54 | // '192.168.0.2', 'fe80::7aca:39ff:feb0:e67d', '78:ca:39:b0:e6:7d'
|
|---|
| 55 | });
|
|---|
| 56 |
|
|---|
| 57 | address('vboxnet', (err, addrs) => {
|
|---|
| 58 | console.log(addrs.ip, addrs.ipv6, addrs.mac);
|
|---|
| 59 | // '192.168.56.1', null, '0a:00:27:00:00:00'
|
|---|
| 60 | });
|
|---|
| 61 | ```
|
|---|
| 62 |
|
|---|
| 63 | ### Get an interface info with family
|
|---|
| 64 |
|
|---|
| 65 | ```js
|
|---|
| 66 | address.interface('IPv4', 'eth1');
|
|---|
| 67 | // { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }
|
|---|
| 68 | ```
|
|---|
| 69 |
|
|---|
| 70 | ### Get DNS servers
|
|---|
| 71 |
|
|---|
| 72 | ```js
|
|---|
| 73 | address.dns((err, addrs) => {
|
|---|
| 74 | console.log(addrs);
|
|---|
| 75 | // ['10.13.2.1', '10.13.2.6']
|
|---|
| 76 | });
|
|---|
| 77 | ```
|
|---|
| 78 |
|
|---|
| 79 | ## License
|
|---|
| 80 |
|
|---|
| 81 | [MIT](LICENSE.txt)
|
|---|
| 82 |
|
|---|
| 83 | <!-- GITCONTRIBUTOR_START -->
|
|---|
| 84 |
|
|---|
| 85 | ## Contributors
|
|---|
| 86 |
|
|---|
| 87 | |[<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/>|
|
|---|
| 88 | | :---: | :---: | :---: | :---: | :---: | :---: |
|
|---|
| 89 | [<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/>
|
|---|
| 90 |
|
|---|
| 91 | 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`.
|
|---|
| 92 |
|
|---|
| 93 | <!-- GITCONTRIBUTOR_END -->
|
|---|