Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows deny file #576

Open
xbbdc opened this issue Apr 16, 2020 · 12 comments
Open

Windows deny file #576

xbbdc opened this issue Apr 16, 2020 · 12 comments

Comments

@xbbdc
Copy link

xbbdc commented Apr 16, 2020

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
Copy link
Contributor

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

@xbbdc
Copy link
Author

xbbdc commented May 5, 2020

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
Copy link
Contributor

Cool, have you tested it with IPv6 too?

This would require yet another output format....

@xbbdc
Copy link
Author

xbbdc commented May 5, 2020 via email

@spirillen
Copy link
Contributor

Would be great 👍

@xbbdc
Copy link
Author

xbbdc commented May 10, 2020

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.

@spirillen
Copy link
Contributor

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/

@funilrys funilrys pinned this issue Jun 24, 2020
@stale
Copy link

stale bot commented Jul 10, 2020

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 stale bot added the wontfix label Jul 10, 2020
@stale stale bot closed this as completed Jul 17, 2020
@funilrys
Copy link
Member

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

@funilrys funilrys reopened this Jul 29, 2020
@stale stale bot removed the wontfix label Jul 29, 2020
@MdeeDev
Copy link

MdeeDev commented Nov 9, 2022

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
Copy link
Contributor

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
Copy link

MdeeDev commented Nov 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants