const mongodb = require('mongodb');
const net = require('net');
const dns = require('dns').promises;

async function test() {
    // Test DNS resolution
    console.log('Testing DNS resolution...');
    try {
        const res = await dns.resolve4('192.168.0.197');
        console.log('DNS resolve4(192.168.0.197):', res);
    } catch (e) {
        console.log('DNS error:', e.message);
    }

    try {
        const res = await dns.resolve4('mongo');
        console.log('DNS resolve4(mongo):', res);
    } catch (e) {
        console.log('DNS mongo error:', e.message);
    }

    // Test direct socket connection
    console.log('\nTesting direct TCP connection...');
    const socket = net.createConnection(27017, '192.168.0.197');
    socket.on('connect', () => {
        console.log('✅ TCP connection successful to 192.168.0.197:27017');
        socket.destroy();
    });
    socket.on('error', (err) => {
        console.log('❌ TCP connection error:', err.message);
    });
}

test();
