码迷,mamicode.com
首页 > Web开发 > 详细

node.js获取ip及mac

时间:2018-05-22 10:39:48      阅读:472      评论:0      收藏:0      [点我收藏+]

标签:this   span   mil   work   node.js   obj   nod   ddr   ace   

;
(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

标签:this   span   mil   work   node.js   obj   nod   ddr   ace   

原文地址:https://www.cnblogs.com/ytxiao/p/9070568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!