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

Add IPv6 in "How to protect a website with Cloudflare without exposing ports to the Internet" #837

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions tutorials/cloudflare-website-protect/01.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ import json

HETZNER_API_TOKEN = "YOUR_HETZNER_API_TOKEN"
HETZNER_FIREWALL_ID = "YOUR_HETZNER_FIREWALL_ID"
def get_cloudflare_ips():
response = requests.get('https://www.cloudflare.com/ips-v4')
def get_cloudflare_ips(version):
url = "https://www.cloudflare.com/ips-v" + version
print("Getting IPs from " + url)
response = requests.get(url)
if response.status_code == 200:
return response.text.strip().split('\n')
else:
Expand Down Expand Up @@ -177,8 +179,13 @@ def whitelist_ips_in_hetzner(ip_ranges):
print("Failed to whitelist IPs in Hetzner Firewall", response.json())

if __name__ == "__main__":
cloudflare_ips = get_cloudflare_ips()
whitelist_ips_in_hetzner(cloudflare_ips)
cloudflare_ips_v4 = get_cloudflare_ips("4")
cloudflare_ips_v6 = get_cloudflare_ips("6")
combined_ips = cloudflare_ips_v4 + cloudflare_ips_v6
print("Whitelisting these IPs:")
for ip in combined_ips:
print(ip)
whitelist_ips_in_hetzner(combined_ips)
```

## Step 5 - Running and automating the script
Expand Down