Files
migu_video/utils/net.js
develop202 c0ce28f776 添加vivid
2025-12-22 14:00:25 +08:00

40 lines
956 B
JavaScript

import os from "os"
// const controller = new AbortController();
// const timeoutId = setTimeout(() => controller.abort(), 15000);
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
}
async function fetchUrl(url, opts = {}) {
// opts["signal"] = controller.signal
const res = await fetch(url, opts)
.then(r => r.json())
.catch(err => console.log(err))
// clearTimeout(timeoutId);
return res
}
export {
getLocalIPv, fetchUrl
}