1
0

hosts/web-2: Block Alibaba Cloud because of scraper bots

This commit is contained in:
2025-07-18 23:55:33 +02:00
parent 9b05a008bb
commit 5bd15927d5
5 changed files with 895 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env python3
import requests
blocked_asns = [
"45102", # Alibaba (US) Technology Co., Ltd.
]
r = requests.get('https://bgp.tools/table.txt', stream=True, headers={
"User-Agent": "https://git.clerie.de/clerie/nixfiles",
})
with open("hosts/web-2/blocked-prefixes.txt", "w") as blocked_ips_file:
for line in r.iter_lines(decode_unicode=True):
ip, asn = line.split()
if asn in blocked_asns:
if ":" in ip:
blocked_ips_file.write(f"ip6tables -I nixos-fw -s {ip} -j nixos-fw-refuse\n")
else:
blocked_ips_file.write(f"iptables -I nixos-fw -s {ip} -j nixos-fw-refuse\n")