Skip to content

Commit

Permalink
Update root.js
Browse files Browse the repository at this point in the history
  • Loading branch information
2M4U authored Mar 3, 2022
1 parent 120e05c commit e13b173
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions lib/src/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,31 @@ const { exec } = require("child_process");
const regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g;

class Root {
async CheckIP() {
async ipBlocker() {
for (const ipAddress of ips) {
switch (isPrivateIP(ipAddress)) {
case true:
console.timeLog(ipAddress);
break;
case false:
await new Root().Execute(ipAddress);
//console.log(ipAddress);
if (ipAddress.match(regex)) {
let { error, stdout, stderr } = await exec(
`sudo iptables -A INPUT -s ${ipAddress} -j DROP`
);
if (stderr) {
return console.log(`${stderr}`);
}
if (error !== null) {
console.log(`exec error: ${error}`);
}
console.log(`${ipAddress} Dropped.`);

let { stdout } = await exec("sudo iptables-save");
}
break;
default:
}
}
}
async Execute(ip) {
if (ip.match(regex)) {
exec(`sudo iptables -A INPUT -s ${ip} -j DROP`, (error, stdout, stderr) => {
if (stderr) {
return console.log(`${stderr}`);
}
if (error !== null) {
console.log(`exec error: ${error}`);
}

return console.log(`${ip} Dropped.`);
}
);
exec(`sudo iptables-save`, (error, stdout, stderr) => {
//console.log(stdout)
});
}
}
}
};

module.exports = new Root();

0 comments on commit e13b173

Please sign in to comment.