You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

19 lines
563 B

const os = require('node:os');
class IpUtil {
static networkInterfaces = os.networkInterfaces(); // 私有静态属性,用于缓存网络接口信息
static getLocalIPs() {
let ipAddresses = [];
for (const face in this.networkInterfaces) {
for (const address of this.networkInterfaces[face]) {
if (address.family === 'IPv4' && !address.internal) {
ipAddresses.push(address.address);
}
}
}
return ipAddresses;
}
}
module.exports = IpUtil;