feat: ✨ add china isp and update readme
This commit is contained in:
parent
664cea5103
commit
1154728b61
|
@ -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 每天自动更新
|
修改自 [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`
|
设置transmission的URL阻止清单`https://github.com/jqtmviyu/Transmission-block-xunlei-pcdn/raw/main/transmission_blacklist.gz`
|
||||||
|
|
||||||
### 定时更新
|
### 定时更新
|
||||||
|
|
|
@ -4,39 +4,40 @@ import re
|
||||||
|
|
||||||
import requests
|
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)
|
response = requests.get(url)
|
||||||
lines = response.text.splitlines()
|
lines = response.text.splitlines()
|
||||||
|
|
||||||
processed_lines = []
|
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line or line.startswith("#"):
|
if not line or line.startswith("#"):
|
||||||
continue
|
continue
|
||||||
# 检查是否是合法的IP地址或CIDR
|
# 过滤掉注释
|
||||||
if re.match(r"(\d{1,3}\.){3}\d{1,3}(\/\d{1,2})?$", line) or re.match(
|
if re.match(r"^\d", line):
|
||||||
r"([a-fA-F0-9:]+)(\/\d{1,3})?$", line
|
|
||||||
):
|
|
||||||
if "/" in line:
|
if "/" in line:
|
||||||
network = ipaddress.ip_network(line, strict=False)
|
network = ipaddress.ip_network(line, strict=False)
|
||||||
ip_range = f"{network.network_address}-{network.broadcast_address}"
|
ip_range = f"{network.network_address}-{network.broadcast_address}"
|
||||||
|
elif "-" in line:
|
||||||
|
ip_range = line
|
||||||
else:
|
else:
|
||||||
ip_range = f"{line}-{line}"
|
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:
|
with open(f"{output_file_name}.txt", "w", encoding="utf-8") as file:
|
||||||
for line in processed_lines:
|
for line in processed_lines:
|
||||||
file.write(line + "\n")
|
file.write(line + "\n")
|
||||||
|
|
||||||
with gzip.open(f"{output_file_name}.gz", "wt", encoding="utf-8") as file:
|
with gzip.open(f"{output_file_name}.gz", "wt", encoding="utf-8") as file:
|
||||||
for line in processed_lines:
|
for line in processed_lines:
|
||||||
file.write(line + "\n")
|
file.write(line + "\n")
|
||||||
|
|
||||||
|
|
||||||
# 调用函数处理远程文件并压缩为.gz格式
|
|
||||||
process_blacklist(
|
|
||||||
"https://raw.githubusercontent.com/PBH-BTN/BTN-Collected-Rules/main/combine/all.txt",
|
|
||||||
"transmission_blacklist",
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue