Skip to content

Instantly share code, notes, and snippets.

@ncruces
Last active September 5, 2019 01:51
Show Gist options
  • Save ncruces/7043ad10712e983cee73be27320fdf2c to your computer and use it in GitHub Desktop.
Save ncruces/7043ad10712e983cee73be27320fdf2c to your computer and use it in GitHub Desktop.
Whitelist Cloudflare's IP addresses in a Windows Firewall rule
param(
[Parameter(Mandatory=$true)]
[String]$rule
)
$ipv4 = (Invoke-WebRequest -UseBasicParsing -Uri "https://www.cloudflare.com/ips-v4").Content
$ipv6 = (Invoke-WebRequest -UseBasicParsing -Uri "https://www.cloudflare.com/ips-v6").Content
$ips = ($ipv4 + $ipv6).TrimEnd().Split([Environment]::NewLine)
Set-NetFirewallRule -DisplayName $rule -RemoteAddress $ips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment