Node.js获取本机IP

function getIPAdress() {
    var interfaces = require('os').networkInterfaces();  
    for (var devName in interfaces) {    
        var iface = interfaces[devName];      
        for (var i = 0; i < iface.length; i++) {
            var alias = iface[i];
            if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
                return alias.address;
            }
        }  
    }
}
posted @ 2019-03-14 22:52  月半流云  阅读(3187)  评论(0编辑  收藏  举报