node.js獲取ip及mac
阿新 • • 發佈:2018-05-22
node.js res ces FN elf mil func require net
; (function (win) { var os = require(‘os‘); var ifaces = os.networkInterfaces(); function NetworkUtil() { var _self = this; this.getMac = function(family){ var mac = ‘‘; Object.keys(ifaces).forEach(function (ifname) { ifaces[ifname].forEach(function (iface) { if (family !== iface.family || iface.internal !== false) { return; } mac = iface.mac; }); }); return mac; } this.getIP = function(family){var ip = ‘‘; Object.keys(ifaces).forEach(function (ifname) { ifaces[ifname].forEach(function (iface) { if (family !== iface.family || iface.internal !== false) { return; } ip= iface.address; }); }); return ip; } } win.global_NetworkUtil = new NetworkUtil(); })(window);
node.js獲取ip及mac