add node-getmac modules

This commit is contained in:
life
2018-12-11 17:30:54 +08:00
parent 17e65292a5
commit ec6ab9efdb
5 changed files with 132 additions and 0 deletions

36
node_modules/node-getmac/index.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
/**
* @file get local mac address
* @author liulangyu(liulangyu90316@gmail.com)
*/
var execSync = require('child_process').execSync;
var platform = process.platform;
module.exports = (function () {
var cmd = {
win32: 'getmac',
darwin: 'ifconfig -a',
linux: 'ifconfig -a || ip link'
}[platform];
var regStr = '((?:[a-z0-9]{2}[:-]){5}[a-z0-9]{2})';
var macReg = new RegExp('ether\\s' + regStr + '\\s', 'i');
try {
var data = execSync(cmd).toString();
var res = {
win32: new RegExp(regStr, 'i').exec(data),
darwin: macReg.exec(data),
linux: macReg.exec(data)
}[platform];
if (res) {
return res[1];
}
}
catch (e) {
return '';
}
})();