Files
iptv-live/scan.sh
T

40 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# 慢速枚举 2409:8087:2001:20:2800:0:df6e:eb* CDN 上的频道编号。
# 为什么要慢/要轮换: 该 CDN 在 ~70-150 个快速请求后会把客户端拉黑几分钟(全部 000),
# 且每个编号只在一个「主机×层级×token」组合上有效,所以要试多种组合。
# 用法: ./scan.sh <起始id> <结束id> 结果追加到 scratch/scan/hits.tsv,已完成 id 记在 done.txt(可续跑)
set -uo pipefail
cd "$(dirname "$0")" || exit 1
mkdir -p scratch/scan
H=scratch/scan/hits.tsv; D=scratch/scan/done.txt; L=scratch/scan/scan.log
touch "$H" "$D"
from=${1:-3221227400}; to=${2:-3221227999}
# 组合: 标签|URL前缀
combos=(
"eb0b-L3|http://[2409:8087:2001:20:2800:0:df6e:eb0b]/wh7f454c46tw993550557_162751766/ott.mobaibox.com/PLTV/3/224"
"eb18-L3|http://[2409:8087:2001:20:2800:0:df6e:eb18]/wh7f454c46tw2482771376_951312812/ott.mobaibox.com/PLTV/3/224"
"eb11-L4|http://[2409:8087:2001:20:2800:0:df6e:eb11]:80/ott.mobaibox.com/PLTV/4/224"
"eb09-L4|http://[2409:8087:2001:20:2800:0:df6e:eb09]:80/ott.mobaibox.com/PLTV/4/224"
)
n=0
for id in $(seq "$from" "$to"); do
grep -qx "$id" "$D" && continue
for c in "${combos[@]}"; do
tag=${c%%|*}; base=${c#*|}
code=$(curl -g -s -m 8 -o /dev/null -w '%{http_code}' "$base/$id/index.m3u8" 2>/dev/null)
if [ "$code" = "200" ]; then
printf '%s\t%s\n' "$id" "$tag" >> "$H"
echo "$(date +%H:%M:%S) HIT $id $tag" >> "$L"
break
fi
case "$code" in 000|429|503) echo "$(date +%H:%M:%S) THROTTLE $id $tag code=$code -> pause 90s" >> "$L"; sleep 90 ;; esac
sleep 2
done
echo "$id" >> "$D"
n=$((n+1))
[ $((n % 20)) -eq 0 ] && echo "$(date +%H:%M:%S) progress $id (hits=$(wc -l < "$H"))" >> "$L"
done
echo "$(date +%H:%M:%S) DONE $from-$to hits=$(wc -l < "$H")" >> "$L"