getMac = function (opts, next) {
var command, data, extractMac, ref;
ref = extractOptsAndCallback(opts, next), opts = ref[0], next = ref[1];
data = opts.data;
if (data == null) {
data = null;
}
command = isWindows ? "getmac" : "ifconfig -a || ip link";
extractMac = function(data, next) {
var err, isZero, macAddress, match, result;
result = null;
while (match = macRegex.exec(data)) {
macAddress = match[0];
isZero = zeroRegex.test(macAddress);
if (isZero === false) {
if (result == null) {
result = macAddress;
}
}
}
if (result === null) {
err = new Error('could not determine the mac address from:\n' + data);
return next(err);
}
return next(null, result);
};
if (data) {
return extractMac(data, next);
} else {
return exec(command, function(err, stdout, stderr) {
if (err) {
return next(err);
}
return extractMac(stdout, next);
});
}
}...
1. Install Globally: `install -g getmac`
2. Run with: `getmac-node`
### API
``` javascript
// Fetch the computer's mac address
require('getmac').getMac(function(err,macAddress){
if (err) throw err
console.log(macAddress)
})
// Validate that an address is a mac address
if ( require('getmac').isMac("e4:ce:8f:5b:a7:fc") ) {
console.log('valid mac')
...isMac = function (macAddress) {
var ref;
return ((ref = String(macAddress).match(macRegex)) != null ? ref.length : void 0) === 1;
}...
// Fetch the computer's mac address
require('getmac').getMac(function(err,macAddress){
if (err) throw err
console.log(macAddress)
})
// Validate that an address is a mac address
if ( require('getmac').isMac("e4:ce:8f:5b:a7:fc") ) {
console.log('valid mac')
}
else {
console.log('invalid mac')
}
```
...