node.js获取ip及mac
Posted 草根玉堂
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node.js获取ip及mac相关的知识,希望对你有一定的参考价值。
; (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的主要内容,如果未能解决你的问题,请参考以下文章