feat!: find default IP segment file at the location of the executable

This commit is contained in:
scientificworld 2023-06-30 19:37:28 +08:00
parent 133924d169
commit ccfd1edb8c
No known key found for this signature in database
GPG Key ID: 26E695328487D75E
2 changed files with 10 additions and 4 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,21 @@ import (
"strconv"
"strings"
"time"
"path/filepath"
)
const defaultInputFile = "ip.txt"
func getDefaultInputFile() string {
exe, _ := os.Executable()
sym, _ := filepath.EvalSymlinks(exe)
log.Print(sym)
return filepath.Dir(sym) + "/ip.txt"
}
var (
// TestAll test all ip
TestAll = false
// IPFile is the filename of IP Rangs
IPFile = defaultInputFile
IPFile = getDefaultInputFile()
IPText string
)
@ -165,7 +171,7 @@ func loadIPRanges() []*net.IPAddr {
}
} else { // 从文件中获取 IP 段数据
if IPFile == "" {
IPFile = defaultInputFile
IPFile = getDefaultInputFile()
}
file, err := os.Open(IPFile)
if err != nil {