import { networkInterfaces } from 'os' /** * Restituisce gli indirizzi IP di rete del sistema, escludendo loopback e bridge Docker. * @returns {string[]} Elenco degli indirizzi IP disponibili. */ export function getNetworkIPs() { const nets = networkInterfaces() const networkIPs = [] for (const name of Object.keys(nets)) { for (const net of nets[name]) { // Esclude loopback (127.0.0.1), indirizzi non IPv4 e bridge Docker (172.17.x.x, 172.18.x.x). if (net.family === 'IPv4' && !net.internal && !net.address.startsWith('172.17.') && !net.address.startsWith('172.18.')) { networkIPs.push(net.address) } } } return networkIPs } /** * Stampa il riepilogo di avvio del server con gli URL di accesso. * @param {number} port - Porta sulla quale il server e in ascolto. */ export function printServerInfo(port = 5173) { const networkIPs = getNetworkIPs() console.log(`\nSegnapunti Server`) console.log(` Display: http://localhost:${port}/`) console.log(` Controller: http://localhost:${port}/controller`) if (networkIPs.length > 0) { console.log(`\n Da dispositivi remoti:`) networkIPs.forEach(ip => { console.log(` http://${ip}:${port}/controller`) }) } console.log() }