/**
 * Test Pinging 192.168.0.10 & Port 5005 (Sesuai Konfigurasi Asli Fingerspot Personnel)
 */
const { execSync } = require('child_process');
const net = require('net');

console.log('=======================================================');
console.log(' TESTING ORIGINAL IP 192.168.0.10 (FINGERSPOT DEFAULT)');
console.log('=======================================================');

try {
    console.log('\nPinging 192.168.0.10...');
    const pingRes = execSync('ping -n 3 192.168.0.10', { encoding: 'utf8' });
    console.log(pingRes);
} catch (e) {
    console.log(`❌ Ping 192.168.0.10 Failed: ${e.message.split('\n')[0]}`);
}

function checkPort(ip, port) {
    return new Promise((resolve) => {
        const socket = new net.Socket();
        socket.setTimeout(2000);
        socket.on('connect', () => {
            console.log(` ✅ Port ${port} TERBUKA di ${ip}!`);
            socket.destroy();
            resolve(true);
        });
        socket.on('error', () => { socket.destroy(); resolve(false); });
        socket.on('timeout', () => { socket.destroy(); resolve(false); });
        socket.connect(port, ip);
    });
}

async function run() {
    console.log('\nChecking ports on 192.168.0.10...');
    await checkPort('192.168.0.10', 5005);
    await checkPort('192.168.0.10', 4370);
    await checkPort('192.168.0.10', 8080);

    console.log('\nChecking ports on 192.168.0.50...');
    await checkPort('192.168.0.50', 5005);
    await checkPort('192.168.0.50', 4370);
    await checkPort('192.168.0.50', 8080);
    console.log('=======================================================\n');
}

run();
