github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/containers/compilers/rump/nodejs/node-wrapper/node_modules/macaddress/lib/windows.js (about)

     1  var exec = require('child_process').exec;
     2  
     3  var regexRegex = /[-\/\\^$*+?.()|[\]{}]/g;
     4  
     5  function escape(string) {
     6      return string.replace(regexRegex, '\\$&');
     7  }
     8  
     9  module.exports = function (iface, callback) {
    10      exec("ipconfig /all", function (err, out) {
    11          if (err) {
    12              callback(err, null);
    13              return;
    14          }
    15          var match = new RegExp(escape(iface)).exec(out);
    16          if (!match) {
    17              callback("did not find interface in `ipconfig /all`", null);
    18              return;
    19          }
    20          out = out.substring(match.index + iface.length);
    21          match = /[A-Fa-f0-9]{2}(\-[A-Fa-f0-9]{2}){5}/.exec(out);
    22          if (!match) {
    23              callback("did not find a mac address", null);
    24              return;
    25          }
    26          callback(null, match[0].toLowerCase().replace(/\-/g, ':'));
    27      });
    28  };