0.5.3 • Published 2 years ago

macaddress v0.5.3

Weekly downloads
229,932
License
MIT
Repository
github
Last release
2 years ago

node-macaddress

Build Status

Retrieve MAC addresses in Linux, OS X, and Windows.

A common misconception about MAC addresses is that every host had one MAC address, while a host may have multiple MAC addresses – since every network interface may have its own MAC address.

This library allows to discover the MAC address per network interface and chooses an appropriate interface if all you're interested in is one MAC address identifying the host system (see API + Examples below).

A common misconception about this library is that it reports the mac address of the client that accesses some kind of backend. It does not. Reporting the mac address is not in any way similar to reporting the IP address of the client that accesses your application. This library reports the mac address of the server the application is running on. This useful for example for distributed/scaled applications, for example when generating UUIDs.

Also it seems to be worth noting that this library is not intended to be used in a browser. There is no web api reporting the mac address of the machine (and that is a good thing).

Features:

  • works on Linux, Mac OS X, Windows, and on most UNIX systems.
  • node ≥ 0.12 and io.js report MAC addresses in os.networkInterfaces() this library utilizes this information when available.
  • also features a sane replacement for os.networkInterfaces() (see API + Examples below).
  • works with stoneage node versions ≥ v0.8 (...)
  • Promise support

Usage

npm install --save macaddress
var macaddress = require('macaddress');

API + Examples

(async)  .one(iface, callback) → string
(async)  .one(iface)           → Promise<string>
(async)  .one(callback)        → string
(async)  .all()                → Promise<{ iface: { type: address } }>
(async)  .all(callback)        → { iface: { type: address } }
(sync)   .networkInterfaces()  → { iface: { type: address } }

.one([iface], callback)

Retrieves the MAC address of the given iface.

If iface is omitted, this function automatically chooses an appropriate device (e.g. eth0 in Linux, en0 in OS X, etc.).

Without iface parameter:

macaddress.one(function (err, mac) {
  console.log("Mac address for this host: %s", mac);  
});

or using Promise

macaddress.one().then(function (mac) {
  console.log("Mac address for this host: %s", mac);  
});
→ Mac address for this host: ab:42:de:13:ef:37

With iface parameter:

macaddress.one('awdl0', function (err, mac) {
  console.log("Mac address for awdl0: %s", mac);  
});

or using Promise

macaddress.one('awdl0').then(function (mac) {
  console.log("Mac address for awdl0: %s", mac);  
});
→ Mac address for awdl0: ab:cd:ef:34:12:56

.all(callback)

Retrieves the MAC addresses for all non-internal interfaces.

macaddress.all(function (err, all) {
  console.log(JSON.stringify(all, null, 2));
});

or using Promise

macaddress.all().then(function (all) {
  console.log(JSON.stringify(all, null, 2));
});
{
  "en0": {
    "ipv6": "fe80::cae0:ebff:fe14:1da9",
    "ipv4": "192.168.178.20",
    "mac": "ab:42:de:13:ef:37"
  },
  "awdl0": {
    "ipv6": "fe80::58b9:daff:fea9:23a9",
    "mac": "ab:cd:ef:34:12:56"
  }
}

.networkInterfaces()

A useful replacement of os.networkInterfaces(). Reports only non-internal interfaces.

console.log(JSON.stringify(macaddress.networkInterfaces(), null, 2));
{
  "en0": {
    "ipv6": "fe80::cae0:ebff:fe14:1dab",
    "ipv4": "192.168.178.22"
  },
  "awdl0": {
    "ipv6": "fe80::58b9:daff:fea9:23a9"
  }
}
@theia/plugin-extcaleva-mtratomsecuremicrosecuremicrosecuremicroapi@ecoenghk/skymon_gwcityadpro_player@byteinspire/clihomekit-ws2801noty-cli@infinitebrahmanuniverse/nolb-maca@everything-registry/sub-chunk-2118network2useseneca-mitesearch-input-reactsearch-list-reactstaticipdigital-keyboard-demosqdm-audit-loggerqdm-loggerrednomicricequant-mac-addresssourcejselectron-managerdkaframeworkopenmv-botscarousel-reactpk-app-pkgmgtpk-app-pkgmgt2plttradewolskill-cmdyandex-homekit@codeanywhere/theia-plugin-extpact-coffee-cli-temp-electron-manager-somiiboaudit-logger-qdmbosstrader@dkaframework/iotnomalism_npcaz-iot-biaz-iot-bi-test@46and2/vuedalsarp-validatorflorofing-heartbeateventsquare-gate@hankts/shopify-cli-kit@greminder/bootstrap-material-design@hyperjumptech/monika@ektx/v-book@firesoon/micro-devtool@facilicom/gbaiobroker.yahka@pinpt/react-componentsiot-client@radjs/ui@remote.it/corekeeplocalkalamakafirchain-tetris@rochismo/net-utilsvuedals@ngxvoice/ngx-voicelistnerlbanrights@shopify/cli-kit@shoplinedev/cli-kitkii-gateway-agent@panneerselvam/qdm-audit-logger@panneerselvam/qdmlogger@panneerselvam/qdmlogger-testvue-authenticate-serviceiservers@lokier/cli-shared-utilshzero-cli-uuimicrosecureauthmineflayer-auto-totem@zalastax/nolb-mac@wujibase/wuji-clinetscreens-player-commonappcd-machine-id@wetrial/uikomodo-sdkzap-climtr-dashboardHeartBeatWoT_pi@vui-admin/buildmy-temp-packageangel-broking-clinode-pserverfhir2umi-uiultra-bridgeumbra-analytics-moduleuuid-1345uuid-sequentialverify-javascript-sdkvenom_robotics
0.5.3

2 years ago

0.5.2

3 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.3.0

4 years ago

0.4.0

4 years ago

0.2.9

6 years ago

0.2.8

9 years ago

0.2.7

9 years ago

0.2.6

9 years ago