mirror of
https://github.com/leanote/desktop-app.git
synced 2025-10-17 08:38:18 +00:00
add node-getmac modules
This commit is contained in:
36
node_modules/node-getmac/index.js
generated
vendored
Normal file
36
node_modules/node-getmac/index.js
generated
vendored
Normal 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 '';
|
||||
}
|
||||
})();
|
Reference in New Issue
Block a user