windows.js 832 B

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