feat: add china isp and update readme

This commit is contained in:
jqtmviyu 2024-08-28 23:05:47 +08:00
parent 664cea5103
commit 1154728b61
2 changed files with 25 additions and 22 deletions

View File

@ -48,6 +48,8 @@ PATH=/usr/sbin:/usr/bin:/sbin:/bin
修改自 [PBH-BTN/BTN-Collected-Rules](https://github.com/PBH-BTN/BTN-Collected-Rules) 的all.txt, github action 每天自动更新
新增常见数据中心ip段: [isp/cn](https://github.com/zealic/autorosvpn/tree/master/isp/cn)
设置transmission的URL阻止清单`https://github.com/jqtmviyu/Transmission-block-xunlei-pcdn/raw/main/transmission_blacklist.gz`
### 定时更新

View File

@ -4,27 +4,35 @@ import re
import requests
output_file_name = "transmission_blacklist"
def process_blacklist(url, output_file_name):
upstream_urls = [
"https://raw.githubusercontent.com/PBH-BTN/BTN-Collected-Rules/main/combine/all.txt",
"https://raw.githubusercontent.com/zealic/autorosvpn/master/isp/cn/route-isp-chinanet.txt", # 中国电信
"https://raw.githubusercontent.com/zealic/autorosvpn/master/isp/cn/route-isp-cn-cmcc.txt", # 中国移动
"https://raw.githubusercontent.com/zealic/autorosvpn/master/isp/cn/route-isp-cncgroup.txt", # 中国联通
"https://raw.githubusercontent.com/zealic/autorosvpn/master/isp/cn/route-isp-cn-crtc.txt", # 中国铁通
]
processed_lines = set()
for url in upstream_urls:
response = requests.get(url)
lines = response.text.splitlines()
processed_lines = []
for line in lines:
line = line.strip()
if not line or line.startswith("#"):
continue
# 检查是否是合法的IP地址或CIDR
if re.match(r"(\d{1,3}\.){3}\d{1,3}(\/\d{1,2})?$", line) or re.match(
r"([a-fA-F0-9:]+)(\/\d{1,3})?$", line
):
# 过滤掉注释
if re.match(r"^\d", line):
if "/" in line:
network = ipaddress.ip_network(line, strict=False)
ip_range = f"{network.network_address}-{network.broadcast_address}"
elif "-" in line:
ip_range = line
else:
ip_range = f"{line}-{line}"
processed_lines.append(f"btn:{ip_range}")
processed_lines.add(f"btn:{ip_range}")
with open(f"{output_file_name}.txt", "w", encoding="utf-8") as file:
for line in processed_lines:
@ -33,10 +41,3 @@ def process_blacklist(url, output_file_name):
with gzip.open(f"{output_file_name}.gz", "wt", encoding="utf-8") as file:
for line in processed_lines:
file.write(line + "\n")
# 调用函数处理远程文件并压缩为.gz格式
process_blacklist(
"https://raw.githubusercontent.com/PBH-BTN/BTN-Collected-Rules/main/combine/all.txt",
"transmission_blacklist",
)