nodejs 获取电脑ip地址

代码:

const os = require(os);
///获取本机ip///
function getIPAdress() {
    var interfaces = 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;
            }
        }
    }
}
const myHost = getIPAdress();

 

nodejs 获取电脑ip地址

上一篇:什么是 Apache Kafka?


下一篇:Notepad++强大的代码补全和代码提示功能的方法