Skip to content

Commit

Permalink
修复 IP 解析不够随机的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
XIU2 committed Nov 17, 2021
1 parent 9471094 commit ea46fc5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ https://github.com/XIU2/CloudflareSpeedTest
}

func main() {
go checkUpdate() // 检查版本更新
go checkUpdate() // 检查版本更新
task.InitRandSeed() // 置随机数种子

fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version)

Expand All @@ -123,7 +124,7 @@ func endPrint() {
return
}
if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
fmt.Printf("\n按下 回车键 或 Ctrl+C 退出。")
fmt.Printf("按下 回车键 或 Ctrl+C 退出。")
var pause int
fmt.Scanln(&pause)
}
Expand Down
5 changes: 4 additions & 1 deletion task/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ var (
IPFile = defaultInputFile
)

func randIPEndWith(num byte) byte {
func InitRandSeed() {
rand.Seed(time.Now().UnixNano())
}

func randIPEndWith(num byte) byte {
return byte(rand.Intn(int(num)))
}

Expand Down
2 changes: 1 addition & 1 deletion utils/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ func (s DownloadSpeedSet) Print(ipv6 bool) {
fmt.Printf(dataFormat, dateString[i][0], dateString[i][1], dateString[i][2], dateString[i][3], dateString[i][4], dateString[i][5])
}
if !noOutput() {
fmt.Printf("\n完整测速结果已写入 %v 文件,可使用记事本/表格软件查看。", Output)
fmt.Printf("\n完整测速结果已写入 %v 文件,可使用记事本/表格软件查看。\n", Output)
}
}

0 comments on commit ea46fc5

Please sign in to comment.