mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-15 23:55:50 +00:00
37 lines
792 B
JavaScript
37 lines
792 B
JavaScript
/**
|
|
* @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 '';
|
|
}
|
|
})();
|