2026-02-10 09:53:46 +01:00
|
|
|
import { networkInterfaces } from 'os'
|
2026-06-20 15:42:57 +02:00
|
|
|
import { readFileSync, existsSync } from 'fs'
|
|
|
|
|
import { execSync } from 'child_process'
|
|
|
|
|
|
|
|
|
|
function isWSL() {
|
|
|
|
|
try {
|
|
|
|
|
return existsSync('/proc/sys/kernel/osrelease') &&
|
|
|
|
|
readFileSync('/proc/sys/kernel/osrelease', 'utf8').toLowerCase().includes('microsoft')
|
|
|
|
|
} catch { return false }
|
|
|
|
|
}
|
2026-02-10 09:53:46 +01:00
|
|
|
|
|
|
|
|
export function getNetworkIPs() {
|
2026-06-20 15:42:57 +02:00
|
|
|
if (isWSL()) {
|
|
|
|
|
try {
|
|
|
|
|
const out = execSync(
|
|
|
|
|
'powershell.exe -NoProfile -Command "Get-NetIPAddress -AddressFamily IPv4 | Select-Object -ExpandProperty IPAddress"',
|
|
|
|
|
{ timeout: 3000 }
|
|
|
|
|
)
|
|
|
|
|
return out.toString().trim().split('\n')
|
|
|
|
|
.map(s => s.trim())
|
|
|
|
|
.filter(ip => ip && !ip.startsWith('127.') && !ip.startsWith('169.254.') && !ip.startsWith('172.'))
|
|
|
|
|
} catch { return [] }
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 09:53:46 +01:00
|
|
|
const nets = networkInterfaces()
|
|
|
|
|
const networkIPs = []
|
|
|
|
|
for (const name of Object.keys(nets)) {
|
|
|
|
|
for (const net of nets[name]) {
|
2026-06-20 15:42:57 +02:00
|
|
|
if (net.family === 'IPv4' && !net.internal) networkIPs.push(net.address)
|
2026-02-10 09:53:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return networkIPs
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 12:22:43 +02:00
|
|
|
export function printServerInfo(port = 3000) {
|
2026-02-10 09:53:46 +01:00
|
|
|
const networkIPs = getNetworkIPs()
|
|
|
|
|
|
|
|
|
|
console.log(`\nSegnapunti Server`)
|
2026-05-12 12:22:43 +02:00
|
|
|
console.log(` Display: http://127.0.0.1:${port}/display`)
|
|
|
|
|
console.log(` Controller: http://127.0.0.1:${port}/controller`)
|
2026-02-10 09:53:46 +01:00
|
|
|
|
|
|
|
|
if (networkIPs.length > 0) {
|
2026-06-20 15:42:57 +02:00
|
|
|
console.log(`\n Da dispositivi remoti:`)
|
2026-02-10 09:53:46 +01:00
|
|
|
networkIPs.forEach(ip => {
|
2026-06-20 15:42:57 +02:00
|
|
|
console.log(` Display: http://${ip}:${port}/display`)
|
|
|
|
|
console.log(` Controller: http://${ip}:${port}/controller`)
|
2026-02-10 09:53:46 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log()
|
|
|
|
|
}
|