文章目录
- 一、效果:
- 二、实现:
一、效果:
二、实现:
const os = require('os');
function getLocalIpAddress() {
const interfaces = os.networkInterfaces();
for (let key in interfaces) {
const iface = interfaces[key];
for (let i = 0; i < iface.length; i++) {
const alias = iface[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
return alias.address;
}
}
}
return '0.0.0.0';
}
console.log(getLocalIpAddress())