Untitled
unknown
plain_text
2 years ago
2.7 kB
8
Indexable
const maxmind = require('maxmind');
const { exec } = require('child_process');
// Pfad zur GeoIP-Datenbank
const DB_PATH = './Firewall/dbip-country-lite.mmdb';
const allowedCountries = ['DE', 'AT', 'CH']; // Deutschland, Österreich, Schweiz
// Funktion zum Hinzufügen einer Firewall-Regel
function addFirewallRule(ip, port = 80) {
const command = `powershell.exe -Command "New-NetFirewallRule -DisplayName 'Allow ${ip}' -Direction Inbound -Action Allow -Protocol TCP -LocalPort ${port} -RemoteAddress ${ip}"`;
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}:${port}`);
});
}
// Funktion zum Blockieren aller eingehenden Verbindungen
function blockAllInboundTraffic() {
const command = `powershell.exe -Command "New-NetFirewallRule -DisplayName 'Block All Inbound' -Direction Inbound -Action Block -Protocol TCP -LocalPort Any"`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`stderr: ${stderr}`);
return;
}
console.log(`All inbound traffic blocked`);
});
}
// Funktion zum Überprüfen von IP-Adressen und Freischalten, wenn zulässig
function allowSpecificCountries() {
maxmind.open(DB_PATH).then((lookup) => {
// Erstelle eine spezifische Regel für die vorgegebene IP
addFirewallRule('80.133.29.37');
// Theoretisch würde hier Code stehen, um weitere IPs zu überprüfen
// Beispiel-IP-Adressen prüfen
const testIPs = ['123.123.123.123', '95.91.215.109']; // Beispiele
testIPs.forEach(ip => {
const geoData = lookup.get(ip);
if (geoData && allowedCountries.includes(geoData.country.iso_code)) {
console.log(`IP ${ip} is allowed from ${geoData.country.iso_code}`);
addFirewallRule(ip);
} else {
console.log(`IP ${ip} is not allowed.`);
}
});
}).catch(err => {
console.error('Error opening MMDB file:', err);
});
}
// Ausführung der Funktionen
blockAllInboundTraffic(); // Schritt 1: Blockiere alle eingehenden Verbindungen
setTimeout(allowSpecificCountries, 5000); // Schritt 2: Erlaube spezifische Länder nach einer kurzen Verzögerung, um Konflikte zu vermeiden
Editor is loading...
Leave a Comment