Update IPTV Mainland Domain Rules #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update IPTV Mainland Domain Rules | |
on: | |
schedule: | |
- cron: "0 */8 * * *" # 每隔8小时触发一次 | |
workflow_dispatch: # 手动触发 | |
jobs: | |
update-rules: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Install ipcalc | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y ipcalc | |
- name: Fetch IPTVMainland Rules and Chinese IP Databases | |
run: | | |
# 下载 IPTVMainland.list 文件 | |
curl -sSL https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/refs/heads/master/rule/Clash/IPTVMainland/IPTVMainland.list -o IPTVMainland.list | |
# 下载中国大陆IP地址数据库(CIDR格式) | |
curl -sSL https://ispip.clang.cn/all_cn_cidr.txt -o all_cn_cidr.txt | |
# 打印下载的文件内容,查看是否正确 | |
cat all_cn_cidr.txt | |
- name: Process Rules | |
run: | | |
mkdir -p rule # 确保 rule 文件夹存在 | |
echo "# 中国大陆地区 IPTV 域名列表" > rule/IPTVMainland_Domain.list | |
echo "# 每隔8小时更新一次,从 blackmatrix7/ios_rule_script 项目拉取,并去除所有 IP 类规则,仅保留域名规则" >> rule/IPTVMainland_Domain.list | |
echo "# 必须搭配 OpenClash 的“绕过大陆”功能使用" >> rule/IPTVMainland_Domain.list | |
# 处理 IPTVMainland.list 中的 IP-CIDR 规则 | |
while read -r line; do | |
# 调试输出行内容 | |
echo "Processing line: $line" | |
# 判断是否包含 IP-CIDR 规则 | |
if [[ "$line" =~ IP-CIDR ]]; then | |
# 提取 CIDR 地址(获取 / 后的部分) | |
cidr=$(echo "$line" | sed 's/.*IP-CIDR, \([0-9.\/]*\).*/\1/') | |
echo "CIDR extracted: $cidr" | |
# 判断 CIDR 地址是否在中国大陆IP库中 | |
is_china_ip=false | |
while read -r db_cidr; do | |
# 打印正在比对的 CIDR | |
echo "Comparing $cidr with $db_cidr" | |
# 使用 ipcalc 判断 CIDR 是否属于中国大陆范围 | |
if echo "$cidr" | ipcalc -c "$db_cidr" | grep -q "Network is unreachable"; then | |
continue | |
fi | |
# 如果 CIDR 地址在中国大陆IP库中,则标记为中国IP | |
is_china_ip=true | |
break | |
done < all_cn_cidr.txt | |
echo "is_china_ip: $is_china_ip" | |
# 如果不属于中国大陆的 IP-CIDR 规则,则保留 | |
if [ "$is_china_ip" = false ]; then | |
echo "$line" >> rule/IPTVMainland_Domain.list | |
fi | |
else | |
# 非 IP-CIDR 行直接保留 | |
echo "$line" >> rule/IPTVMainland_Domain.list | |
fi | |
done < IPTVMainland.list | |
- name: Commit and Push Changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
# 添加所有新文件,包括规则文件和数据库文件 | |
git add rule/IPTVMainland_Domain.list | |
git add IPTVMainland.list | |
git add all_cn_cidr.txt | |
git commit -m "Update IPTVMainland_Domain.list" | |
git push |