javascript - NodeJS - get MAC address when offline -


similar this question in c#, possible in nodejs mac address(es) of computer when disconnected network?

i have been using macaddress module, works great when user connected network -- if user disconnects, macaddress not return addresses on systems.

i noticed differences between os.networkinterfaces() when user offline/online, differences in behavior across windows/mac , node v10/v12. i'm not sure problem lies here.

i tested getmac module , works fine offline (and online).

you can try this:

require('getmac').getmac(function(err,macaddress){     if (err)  throw err     console.log(macaddress) // 77:31:c2:c5:03:10 }) 

if don't want use module can ask each mac address interface (node >= 0.11):

require('os').networkinterfaces() 

and parse depending of needs.

the result should this:

{ lo0:    [ { address: '::1',        netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',        family: 'ipv6',        mac: '00:00:00:00:00:00',        scopeid: 0,        internal: true },      { address: '127.0.0.1',        netmask: '255.0.0.0',        family: 'ipv4',        mac: '00:00:00:00:00:00',        internal: true },      { address: 'fe80::1',        netmask: 'ffff:ffff:ffff:ffff::',        family: 'ipv6',        mac: '00:00:00:00:00:00',        scopeid: 1,        internal: true } ],   en0:    [ { address: '10.3.162.15',        netmask: '255.255.254.0',        family: 'ipv4',        mac: '77:31:c2:c5:03:10',        internal: false } ],   vboxnet0:    [ { address: '192.168.33.1',        netmask: '255.255.255.0',        family: 'ipv4',        mac: '0a:00:27:00:00:00',        internal: false } ],   en3:    [ { address: '10.3.32.45',        netmask: '255.255.248.0',        family: 'ipv4',        mac: '0c:4d:e7:3d:3d:17',        internal: false } ] } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -