diff --git a/main.js b/main.js index dd39ed2..0d28acc 100644 --- a/main.js +++ b/main.js @@ -2,6 +2,7 @@ const net = require("net") const {spawn,exec} = require("child_process"); const portlist = [21,1433,7777] const host = "0.0.0.0"; +var ipSet = new Set() servermap = new Map() portlist.forEach(i => { @@ -16,15 +17,16 @@ portlist.forEach(i => { console.log(`incomming connection from : ${a.remoteAddress} on port ${i}`) // handle error even on socket instance (prevents the econnreset error) a.on("error", () => {}) - // Handle banning ip + // Add ip to ipSet + ipSet.add(a.remoteAddress) + }) + servermap.set(i, server) +}) - - // const output = spawn("echo", [`-A INPUT -s ${a.remoteAddress} -j DROP`]); - // output.stdout.on("data", () => {console.log(data);}) - - - - exec(`echo -A INPUT -s ${a.remoteAddress} -j DROP`, (error, stdout, stderr) => { +// This interval looks through the ipSet every 30 seconds and if there are an inside, it will ban them and remove them from the Set +setInterval(()=>{ + ipSet.forEach(i => { + exec(`echo -A INPUT -s ${i} -j DROP`, (error, stdout, stderr) => { if (error) { console.log(`error: ${error.message}`); return; @@ -35,10 +37,9 @@ portlist.forEach(i => { } console.log(`stdout: ${stdout}`); }); + ipSet.delete(i) }) - servermap.set(i, server) -}) - +},30000) process.on('uncaughtException', function (err) {