Update IPTV Mainland Domain Rules #3
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: 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 | |
# 下载中国大陆IP地址数据库(域名格式) | |
curl -sSL https://ispip.clang.cn/all_cn.txt -o all_cn.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 | |
# 判断是否包含 IP-CIDR 规则 | |
if [[ "$line" =~ IP-CIDR ]]; then | |
# 提取 CIDR 地址(获取 / 后的部分) | |
cidr=$(echo "$line" | sed 's/.*IP-CIDR, \([0-9.\/]*\).*/\1/') | |
# 判断 CIDR 地址是否在中国大陆IP库中 | |
matched=false | |
while read -r db_cidr; do | |
# 使用 ipcalc 判断 IP 是否在 CIDR 范围内 | |
if echo "$cidr" | ipcalc -c "$db_cidr" | grep -q "Network is unreachable"; then | |
continue | |
fi | |
# 如果 CIDR 地址在中国大陆IP库中,则标记为匹配 | |
matched=true | |
break | |
done < all_cn_cidr.txt | |
if [ "$matched" = false ]; then | |
# 如果 CIDR 地址不在中国大陆IP库中,则保留该行 | |
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 commit -m "Update IPTVMainland_Domain.list" | |
git push |