XIU2/CloudflareSpeedTest · warning
Failed to get the preferred IPv4 address.
Error message
Failed to get the preferred IPv4 address.
What it means
cfst_dnspod.sh runs ./cfst -f ip.txt -n 500 -o result4.csv (line 49, after rm -f result4.csv result6.csv at line 10), then reads preferred_ipv4=$(awk -F, 'NR==2 {print $1}' result4.csv) at line 52. When that is empty the script prints this message at line 56 and skips the whole IPv4 branch (no DNSPod lookup/create/update); execution continues to the IPv6 section.
Source
Thrown at script/cfst_dnspod.sh:56
}
# 更新 DNS 记录
update_dns_record() {
local record_id=$1
local record_type=$2
local ip_address=$3
curl -s -X POST -d "login_token=$dnspod_token&format=json&domain=$dnspod_domain&record_id=$record_id&sub_domain=$dnspod_record&record_type=$record_type&record_line=默认&value=$ip_address" "$dnspod_api_url/Record.Modify"
}
# 运行 CFST v4
./cfst -f ip.txt -n 500 -o result4.csv
# 读取 CSV 文件并提取优选 IPv4 地址
preferred_ipv4=$(awk -F, 'NR==2 {print $1}' result4.csv)
# 检查是否获取到了 IPv4 地址
if [ -z "$preferred_ipv4" ]; then
echo "Failed to get the preferred IPv4 address."
else
echo "BETTER IPv4: $preferred_ipv4"
# 获取 IPv4 记录 ID
ipv4_record_id=$(get_record_id "A")
if [ -n "$ipv4_record_id" ]; then
# 更新 IPv4 记录
update_dns_record "$ipv4_record_id" "A" "$preferred_ipv4"
echo "Updated DNSPod record with IPv4: $preferred_ipv4"
else
# 创建 IPv4 记录
new_ipv4_record_id=$(create_dns_record "A" "$preferred_ipv4")
if [ -n "$new_ipv4_record_id" ]; then
echo "Created DNSPod record with IPv4: $preferred_ipv4"
else
echo "Failed to create DNSPod record with IPv4."
fiView on GitHub (pinned to 1da0c025d7)
Solutions
- Run ./cfst -f ip.txt -n 500 -o result4.csv manually and confirm it executes and writes data rows
- Verify ./cfst is executable and ip.txt exists in the working directory (adjust -n to at most the IP list size)
- Relax -t/-sl filters if the CSV is header-only, then re-run
- Invoke with credentials exported and from the right directory: API_TOKEN='id,token' DOMAIN=example.com SUB_DOMAIN=www bash cfst_dnspod.sh
- Add a file guard before line 52: [ -s result4.csv ] || { echo 'no result4.csv'; exit 1; }
Example fix
# script/cfst_dnspod.sh (before)
preferred_ipv4=$(awk -F, 'NR==2 {print $1}' result4.csv)
# (after)
if [ -s result4.csv ] && [ "$(wc -l < result4.csv)" -ge 2 ]; then
preferred_ipv4=$(awk -F, 'NR==2 {print $1}' result4.csv)
else
preferred_ipv4=''
fi Defensive patterns
Strategy: validation
Validate before calling
[ -x ./cfst ] && [ -f ip.txt ] && [ -n "$API_TOKEN" ] && [ -n "$DOMAIN" ] && [ -n "$SUB_DOMAIN" ] || { echo 'prereqs missing (cfst/ip.txt/API_TOKEN/DOMAIN/SUB_DOMAIN)' >&2; exit 1; } Type guard
is_ipv4(){ [[ $1 =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; }
is_ipv4 "$preferred_ipv4" || echo 'preferred_ipv4 not a valid IPv4' >&2 Prevention
- Export API_TOKEN ('id,token' comma form), DOMAIN, SUB_DOMAIN in the environment/wrapper before running
- Check result4.csv exists and has at least 2 lines after each cfst run; treat absence as a skip signal, not success
- Size -n to your ip.txt (-n 500 is pointless for shorter lists) and relax -t/-sl when the CSV is header-only
When it happens
Trigger: result4.csv missing because cfst never ran (binary not executable, ip.txt absent in CWD) or cfst exited without qualifying IPs; or result4.csv exists with only a header row so awk NR==2 finds nothing.
Common situations: Running from a directory without ./cfst or ip.txt (credentials are env vars — API_TOKEN/DOMAIN/SUB_DOMAIN — so the file requirements are easy to miss); -n 500 exceeding the usable entries in ip.txt; all IPs failed latency filtering; unattended cron with the wrong cwd.
Related errors
- Failed to get the preferred IPv6 address.
- CFST 测速结果 IP 数量为 0,跳过下面步骤...
- CFST 测速结果 IP 数量为 0,跳过下面步骤...
- CFST 测速结果 IP 数量为 0,跳过下面步骤...
- CFST 测速结果 IP 数量为 0,跳过下面步骤...
AI-assisted analysis of XIU2/CloudflareSpeedTest@1da0c025d7 (2026-08-15).
Data as JSON: /api/errors/651f9021d5b05f5d.
Report an issue: GitHub.