Ultimate.Hosts.Blacklist icon indicating copy to clipboard operation
Ultimate.Hosts.Blacklist copied to clipboard

Windows deny file

Open xbbdc opened this issue 4 years ago • 12 comments

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

xbbdc avatar Apr 16 '20 01:04 xbbdc

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

spirillen avatar Apr 16 '20 20:04 spirillen

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

xbbdc avatar May 05 '20 04:05 xbbdc

Cool, have you tested it with IPv6 too?

This would require yet another output format....

spirillen avatar May 05 '20 19:05 spirillen

I can test that tonight.

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


From: spirillen [email protected] Sent: Tuesday, May 5, 2020 1:34:14 PM To: mitchellkrogza/Ultimate.Hosts.Blacklist [email protected] Cc: xbbdc [email protected]; Assign [email protected] 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.

xbbdc avatar May 05 '20 19:05 xbbdc

Would be great :+1:

spirillen avatar May 05 '20 19:05 spirillen

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}

Use this topic to help manage Windows and Windows Server technologies with Windows PowerShell.

xbbdc avatar May 10 '20 17:05 xbbdc

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/

spirillen avatar May 11 '20 00:05 spirillen

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.

stale[bot] avatar Jul 10 '20 05:07 stale[bot]

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

funilrys avatar Jul 29 '20 20:07 funilrys

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

MdeeDev avatar Nov 09 '22 21:11 MdeeDev

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?

spirillen avatar Nov 16 '22 17:11 spirillen

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.

MdeeDev avatar Nov 16 '22 18:11 MdeeDev