This commit is contained in:
test
2025-12-02 17:24:50 +08:00
parent 81781bea7f
commit 290574b945
14 changed files with 220 additions and 260 deletions

27
utils/net.js Normal file
View File

@@ -0,0 +1,27 @@
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
}