This repository has been archived by the owner on Aug 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
/
main.go
67 lines (62 loc) · 1.54 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"github.com/cheggaaa/pb/v3"
"sort"
"sync"
"time"
)
func handleUserInput() {
fmt.Println("请输入扫描协程数(数字越大越快,默认400):")
fmt.Scanln(&pingRoutine)
if pingRoutine <= 0 {
pingRoutine = 400
}
fmt.Println("请输入tcping次数(默认10):")
fmt.Scanln(&pingTime)
if pingTime <= 0 {
pingTime = 10
}
fmt.Println("请输入要测试的下载节点个数(默认10):")
fmt.Scanln(&downloadTestCount)
if downloadTestCount <= 0 {
downloadTestCount = 10
}
fmt.Println("请输入下载测试时间(默认10,单位为秒):")
var downloadSecond int64
fmt.Scanln(&downloadSecond)
if downloadSecond <= 0 {
downloadSecond = 10
}
downloadTestTime = time.Duration(downloadSecond) * time.Second
}
func main() {
initipEndWith()
handleUserInput()
ips := loadFirstIPOfRangeFromFile()
pingCount := len(ips) * pingTime
bar := pb.StartNew(pingCount)
var wg sync.WaitGroup
var mu sync.Mutex
var data = make([]CloudflareIPData, 0)
fmt.Println("开始tcping")
control := make(chan bool, pingRoutine)
for _, ip := range ips {
wg.Add(1)
control <- false
handleProgress := handleProgressGenerator(bar)
go tcpingGoroutine(&wg, &mu, ip, pingTime, &data, control, handleProgress)
}
wg.Wait()
bar.Finish()
bar = pb.StartNew(downloadTestCount)
sort.Sort(CloudflareIPDataSet(data))
fmt.Println("开始下载测速")
for i := 0; i < downloadTestCount; i++ {
_, speed := DownloadSpeedHandler(data[i].ip)
data[i].downloadSpeed = speed
bar.Add(1)
}
bar.Finish()
ExportCsv("./result.csv", data)
}