Ultimate-Hosts-Blacklist / Ultimate.Hosts.Blacklist

The Ultimate Unified Hosts file for protecting your network, computer, smartphones and Wi-Fi devices against millions of bad web sites. Protect your children and family from gaining access to bad web sites and protect your devices and pc from being infected with Malware or Ransomware.
MIT License
1.27k stars 156 forks source link

Windows deny file #576

Open xbbdc opened 4 years ago

xbbdc commented 4 years ago

You can use powershell to import and create a rule to block the IPs.

https://portal.databasemart.com/kb/a327/how-to-block-ip-in-windows-firewall.aspx

spirillen commented 4 years ago

Do you know if this is possible on home/pro as well or only in the server versions?

xbbdc commented 4 years ago

I tested this on both Home and Pro using the powershell version and it works. Using the old netsh doesn't work since it doesn't support variables. There is a caveat though and that is the text file lines have to be in CIDR format, 192.168.0.0/22 etc and only works as admin.

$IP = get-content c:\temp\ip.txt New-NetFirewallRule -DisplayName "_Block Rule" -Direction Inbound –LocalPort Any -Protocol TCP -Action Block -RemoteAddress $IP

spirillen commented 4 years ago

Cool, have you tested it with IPv6 too?

This would require yet another output format....

xbbdc commented 4 years ago

I can test that tonight.

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10


From: spirillen notifications@github.com Sent: Tuesday, May 5, 2020 1:34:14 PM To: mitchellkrogza/Ultimate.Hosts.Blacklist Ultimate.Hosts.Blacklist@noreply.github.com Cc: xbbdc bdelcarpio@outlook.com; Assign assign@noreply.github.com Subject: Re: [mitchellkrogza/Ultimate.Hosts.Blacklist] Windows deny file (#576)

Cool, have you tested it with IPv6 too?

This would require yet another output format....

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHubhttps://github.com/mitchellkrogza/Ultimate.Hosts.Blacklist/issues/576#issuecomment-624262229, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOIJZQG4RG2BUGP4WO22Y43RQBS3NANCNFSM4MJATDRA.

spirillen commented 4 years ago

Would be great :+1:

xbbdc commented 4 years ago

Hey there sorry for the delay. It would be the same command and you can use the same text file, it just has to be in one of these formats:

https://docs.microsoft.com/en-us/powershell/module/netsecurity/new-netfirewallrule?view=win10-ps#parameters Single IPv4 Address: 1.2.3.4 Single IPv6 Address: fe80::1 IPv4 Subnet (by network bit count): 1.2.3.4/24 IPv6 Subnet (by network bit count): fe80::1/48 IPv4 Subnet (by network mask): 1.2.3.4/255.255.255.0 IPv4 Range: 1.2.3.4-1.2.3.7 IPv6 Range: fe80::1-fe80::9

If I put these in a text file and changing one example of the subnet by network mask:

1.2.3.4 fe80::1 1.2.3.4/24 fe80::1/48 2.3.4.5/255.255.255.0 1.2.3.4-1.2.3.7 fe80::1-fe80::9

I can run this command:

$IP = get-content c:\temp\ip.txt New-NetFirewallRule -DisplayName "_Block Rule-example" -Direction Inbound –LocalPort Any -Protocol TCP -Action Block -RemoteAddress $IP

I get the following output showing me they've all been added:

$FormatEnumerationLimit =-1 Get-NetFirewallRule -DisplayName "_Block Rule-example" | Get-NetFirewallAddressFilter

LocalAddress : Any RemoteAddress : {1.2.3.4-1.2.3.7, 1.2.3.0/255.255.255.0, 2.3.4.0/255.255.255.0, 1.2.3.4, fe80::1, fe80::1-fe80::9, fe80::1/48}

New-NetFirewallRule (netsecurity)
Use this topic to help manage Windows and Windows Server technologies with Windows PowerShell.
spirillen commented 4 years ago

Hey @xbbdc would you be up for writing a little wiki or blog(howto) on this at my site?

wiki https://www.mypdns.org/w/ blog https://www.mypdns.org/phame/

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

funilrys commented 4 years ago

Thanks @stalebot but I want to keep this open for information!

MdeeDev commented 1 year ago

Hey, i have made a PowerShell script that does exactly that. It can take the enormous list file from Ultimate.Hosts.Blacklist IPs. It adds multiple block rules in the windows firewall. https://github.com/MdeeDev/firewall-IpBlockList

spirillen commented 1 year ago

Hey, i have made a PowerShell script that does exactly that. It can take the enormous list file from Ultimate.Hosts.Blacklist IPs. It adds multiple block rules in the windows firewall. https://github.com/MdeeDev/firewall-IpBlockList

Do it also cleanup old records on each run?

MdeeDev commented 1 year ago

Hey, i have made a PowerShell script that does exactly that. It can take the enormous list file from Ultimate.Hosts.Blacklist IPs. It adds multiple block rules in the windows firewall. https://github.com/MdeeDev/firewall-IpBlockList

Do it also cleanup old records on each run?

Yes , there is an "Update" option. As long as you provide it with the correct firewall rule name.