Files
develop202-migu_video/utils/net.js
2025-12-02 17:24:50 +08:00

28 lines
608 B
JavaScript

import os from "os"
function getLocalIPv(ver = 4) {
const ips = []
const inter = os.networkInterfaces()
// console.dir(inter, { depth: null })
for (let net in inter) {
// console.dir(net, { depth: null })
// console.log()
for (let netPort of inter[net]) {
// netPort = inter[net][netPort]
// console.dir(netPort, { depth: null })
if (netPort.family === `IPv${ver}`) {
// console.dir(netPort, { depth: null })
ips.push(netPort.address)
}
}
}
// console.log()
// console.dir(ips, { depth: null })
return ips
}
export {
getLocalIPv
}