This commit is contained in:
scientificworld 2024-02-13 10:37:35 -08:00 committed by GitHub
commit 9b0f5a223f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View File

@ -92,7 +92,7 @@ https://github.com/XIU2/CloudflareSpeedTest
flag.Float64Var(&task.MinSpeed, "sl", 0, "下载速度下限")
flag.IntVar(&utils.PrintNum, "p", 10, "显示结果数量")
flag.StringVar(&task.IPFile, "f", "ip.txt", "IP段数据文件")
flag.StringVar(&task.IPFile, "f", "", "IP段数据文件")
flag.StringVar(&task.IPText, "ip", "", "指定IP段数据")
flag.StringVar(&utils.Output, "o", "result.csv", "输出结果文件")

View File

@ -9,15 +9,28 @@ import (
"strconv"
"strings"
"time"
"path/filepath"
)
const defaultInputFile = "ip.txt"
func getDefaultInputFile() string {
exe, err := os.Executable()
if err != nil {
log.Fatal(err)
}
sym, err := filepath.EvalSymlinks(exe)
if err != nil {
log.Fatal(err)
}
return filepath.Join(filepath.Dir(sym), defaultInputFile)
}
var (
// TestAll test all ip
TestAll = false
// IPFile is the filename of IP Rangs
IPFile = defaultInputFile
IPFile = getDefaultInputFile()
IPText string
)
@ -165,7 +178,11 @@ func loadIPRanges() []*net.IPAddr {
}
} else { // 从文件中获取 IP 段数据
if IPFile == "" {
IPFile = defaultInputFile
if _, err := os.Stat(defaultInputFile); err != nil {
IPFile = getDefaultInputFile()
} else {
IPFile = defaultInputFile
}
}
file, err := os.Open(IPFile)
if err != nil {