XIU2/CloudflareSpeedTest · error

err

Error message

err

What it means

task/ip.go:170-173 calls os.Open(IPFile) and log.Fatal(err) on failure, terminating the program before any testing starts. IPFile defaults to ip.txt and is only bypassed when -ip is given (the IPText branch at ip.go:152). The raw *PathError is printed, so the message includes 'no such file or directory' or 'permission denied' plus the path.

Source

Thrown at task/ip.go:172

		for _, IP := range IPs {
			IP = strings.TrimSpace(IP) // 去除首尾的空白字符(空格、制表符、换行符等)
			if IP == "" {              // 跳过空的(即开头、结尾或连续多个 ,, 的情况)
				continue
			}
			ranges.parseCIDR(IP) // 解析 IP 段,获得 IP、IP 范围、子网掩码
			if isIPv4(IP) {      // 生成要测速的所有 IPv4 / IPv6 地址(单个/随机/全部)
				ranges.chooseIPv4()
			} else {
				ranges.chooseIPv6()
			}
		}
	} else { // 从文件中获取 IP 段数据
		if IPFile == "" {
			IPFile = defaultInputFile
		}
		file, err := os.Open(IPFile)
		if err != nil {
			log.Fatal(err)
		}
		defer file.Close()
		scanner := bufio.NewScanner(file)
		for scanner.Scan() { // 循环遍历文件每一行
			line := strings.TrimSpace(scanner.Text()) // 去除首尾的空白字符(空格、制表符、换行符等)
			if line == "" {                           // 跳过空行
				continue
			}
			ranges.parseCIDR(line) // 解析 IP 段,获得 IP、IP 范围、子网掩码
			if isIPv4(line) {      // 生成要测速的所有 IPv4 / IPv6 地址(单个/随机/全部)
				ranges.chooseIPv4()
			} else {
				ranges.chooseIPv6()
			}
		}
	}
	return ranges.ips
}

View on GitHub (pinned to 1da0c025d7)

Solutions

  1. Confirm the file exists at the exact path passed via -f (or place ip.txt next to the binary) and re-run.
  2. Pass an absolute path: ./cfst -f /etc/cfst/ip.txt, especially in scripts/services with a different cwd.
  3. Or skip the file entirely by passing CIDRs inline: -ip 104.16.0.0/12,172.64.0.0/13.
  4. Check permissions (ls -l) and read access if the error says permission denied.

Example fix

# before
./cfst -f ip.txt   # run from another directory -> log.Fatal
# after
./cfst -f "$(dirname "$0")/ip.txt"
# or inline
./cfst -ip 104.16.0.0/12,172.64.0.0/13
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
IP_FILE="${IP_FILE:-ip.txt}"
[[ -r "${IP_FILE}" ]] || { echo "missing/unreadable: ${IP_FILE}"; exit 1; }
./cfst -f "${IP_FILE}"

Prevention

When it happens

Trigger: Running without -ip and without a readable ip.txt in the current working directory; -f pointing to a nonexistent or unreadable path; running the binary from a different directory than where the IP list lives; a BOM/CRLF-mangled filename is not the issue here but a directory without read permission is.

Common situations: Fresh clone/decompress where the user renamed or moved ip.txt; systemd/cron jobs whose WorkingDirectory is not where ip.txt sits; running as a user without read rights on the file; passing a quoted path with spaces incorrectly so the shell splits it.

Related errors


AI-assisted analysis of XIU2/CloudflareSpeedTest@1da0c025d7 (2026-08-15). Data as JSON: /api/errors/ccb6fac321a399da. Report an issue: GitHub.