01-NodeJS获取MAC地址

  • Post author:
  • Post category:其他



一. 关于getmac

node.js没有直接获取mac网卡地址的模块,此时我们需要借助于第三方模块getmac。getmac 可以帮助我们 获取当前机器上的mac地址。gatmac 下载地址为:

https://github.com/bevry/getmac

我们也可以使用命令:
npm install getmac
进行下载安装。这里使用命令进行下载。安装执行该命令后会将getmac下载,效果图如下所示:

此时getmac下载的目录为C:\Users\user\node_modules。


二. 编写代码

1、新建test.js代码如下:
var npm = require('./getmac');//获取mac地址
  
 //获取机器mac地址
 npm.getMac(function(err,macAddress){
     if (err)  throw err;
     var mac = macAddress; //获取mac地址
     console.log(mac);     
 }); 
2、将C:\Users\user\node_modules目录下的getmac复制到test.js所在的目录下。执行即可获得机器mac地址。效果图如下:

转载于:https://my.oschina.net/majorx/blog/3039981