bunnytables/update.py

32 lines
555 B
Python
Raw Permalink Normal View History

2024-07-21 12:30:38 +02:00
import requests
import json
import os
print("Downloading...")
data = requests.get('https://bunnycdn.com/api/system/edgeserverlist').text
ips = json.loads(data)
print("Compiling...")
text = """#!/usr/sbin/nft -f
table inet bunny {
chain input {
type filter hook input priority 10;
tcp dport != 31491 return;
"""
for ip in ips:
text += f" ip saddr {ip} accept;\n"
text += """ drop;
}
}"""
file = open('rules.nft', 'w')
file.write(text)
file.close()
print("Submitting...")
os.system('sudo nft -f rules.nft')