I'v been trying to block all ips of a specific website using netsh advfirewall for an Electron JavaScript application. Here is my code.
const { app, BrowserWindow } = require('electron') const { exec } = require('child_process') const dns = require('dns') const url = require('url') const createWindow = () => { const win = new BrowserWindow({ width: 800, height: 600 }) win.loadFile('Screens/index.html') blockWebsite('littlebigsnake.com') win.setMenu(null) } app.whenReady().then(() => { createWindow() }) function blockWebsite(urlString) { // grab host name from input const { hostname } = url.parse(`http://${urlString}`) // turn hostname into all ips dns.resolve(hostname, 'A', (err, addresses) => { if (err) { console.error(`Error: ${err}`) return } // block each ip address through the firewall addresses.forEach(address => { exec(`netsh advfirewall firewall add rule name="Block ${urlString}" dir=out action=block remoteip=${address}`, (error, stdout, stderr) => { if (error) { console.error(`${error}`) return } console.log(`stdout: ${stdout}`) console.log(`stderr: ${stderr}`) }) }) }) } Here is the error I am getting Error: Command failed: netsh advfirewall firewall add rule name="Block littlebigsnake.com" dir=out action=block remoteip=104.26.9.138
Error: Command failed: netsh advfirewall firewall add rule name="Block littlebigsnake.com" dir=out action=block remoteip=172.67.71.90
Error: Command failed: netsh advfirewall firewall add rule name="Block littlebigsnake.com" dir=out action=block remoteip=104.26.8.138