Get Mac Address in container running node

Hello,

I am trying to get the MAC address of my Balena Fin from within a node instance of a container, How can I do this?

Hi Patrick you should be able to do this simply by running ip addr show eth0 which would give you the details for eth0 ,assuming you have an eth0 ethernet interface.

Thanks Shaun,

That works for the CLI but I cant use that in my node process?

Hi. Just doing a quick search reveals https://www.npmjs.com/package/macaddress for example. Is this something that would suit your needs?

Yup as Florin pointed out that lib or https://www.npmjs.com/package/getmac should do the trick. You can even avoid installing any libs and use the native nodeJS function require('os').networkInterfaces(). You might also need to make sure your container is running with network_mode: host if you are running in a multicontainer setup.

Thanks, I will give this a go