const interfaces = require('os').networkInterfaces();
let IPAddress = '';
for (let devName in interfaces) {
let iface = interfaces[devName];
for (let i = 0; i < iface.length; i++) {
let alias = iface[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
IPAddress = alias.address;
}
}
}
console.log(IPAddress);
Node--获取当前主机ip
最新推荐文章于 2023-11-30 23:45:00 发布