32 lines
555 B
Python
32 lines
555 B
Python
|
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')
|