Skip to content

Update IPTV Mainland Domain Rules #58

Update IPTV Mainland Domain Rules

Update IPTV Mainland Domain Rules #58

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
- 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
# 剔除以 .cn 结尾的行
if [[ "$line" =~ \.cn$ ]]; then
continue
fi
# 判断是否包含 IP-CIDR 规则
if [[ "$line" =~ IP-CIDR ]]; then
# 提取 CIDR 地址(获取 / 后的部分)
cidr=$(echo "$line" | sed 's/.*IP-CIDR, \([0-9.\/]*\).*/\1/')
# 判断 CIDR 地址是否在中国大陆IP库中
is_china_ip=false
while read -r db_cidr; do
# 使用 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
# 如果不属于中国大陆的 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
# 清理临时文件
rm -f IPTVMainland.list all_cn_cidr.txt
- 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 commit -m "Update IPTVMainland_Domain.list" || echo "No changes to commit"
git push