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.
侯晓宇
0cb2601919
|
4 weeks ago | |
---|---|---|
.. | ||
lib | 4 weeks ago | |
LICENSE.txt | 4 weeks ago | |
README.md | 4 weeks ago | |
package.json | 4 weeks ago |
README.md
address
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.
const 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((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
address.interface('IPv4', 'eth1');
// { address: '192.168.1.1', family: 'IPv4', mac: '78:ca:39:b0:e6:7d' }
Get DNS servers
address.dns((err, addrs) => {
console.log(addrs);
// ['10.13.2.1', '10.13.2.6']
});
License
Contributors
fengmk2 |
alsotang |
jkelleyrtp |
mariodu |
mathieutu |
zhangyuheng |
---|---|---|---|---|---|
coolme200 |
whxaxes |
This project follows the git-contributor spec, auto updated at Tue Sep 13 2022 09:09:11 GMT+0800
.