Untitled

 avatar
unknown
plain_text
a year ago
1.6 kB
8
Indexable
const maxmind = require('maxmind');
const { exec } = require('child_process');

// Pfad zur MMDB-Datenbank
const DB_PATH = './path/to/your/dbip-country-lite.mmdb';

// Erlaubte Ländercodes
const ALLOWED_COUNTRIES = ['DE', 'AT', 'CH']; // Deutschland, Österreich, Schweiz

// Funktion zum Hinzufügen einer Firewall-Regel
function addFirewallRule(ip) {
    const command = `powershell.exe -Command "New-NetFirewallRule -DisplayName 'Allow ${ip}' -Direction Inbound -Action Allow -RemoteAddress ${ip} -Protocol TCP"`;
    exec(command, (error, stdout, stderr) => {
        if (error) {
            console.error(`Error: ${error.message}`);
            return;
        }
        if (stderr) {
            console.error(`stderr: ${stderr}`);
            return;
        }
        console.log(`Firewall rule added for ${ip}: ${stdout}`);
    });
}

// Öffne die GeoIP2-Datenbank
maxmind.open(DB_PATH)
    .then((lookup) => {
        // Hier müsstest du deine IP-Adressen prüfen, zum Beispiel:
        const testIPs = ['80.133.29.37', '192.168.1.1']; // Füge hier realistische IP-Adressen hinzu
        testIPs.forEach(ip => {
            const geoData = lookup.get(ip);
            if (geoData && ALLOWED_COUNTRIES.includes(geoData.country.iso_code)) {
                console.log(`IP ${ip} is allowed from ${geoData.country.names.en}`);
                addFirewallRule(ip);
            } else {
                console.log(`IP ${ip} is not allowed.`);
            }
        });
    })
    .catch(err => {
        console.error('Error opening MMDB file:', err);
    });
Editor is loading...
Leave a Comment