-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
191 lines (168 loc) · 3.69 KB
/
Copy pathtypes.go
File metadata and controls
191 lines (168 loc) · 3.69 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package ipcheck
import (
"fmt"
"net"
"strconv"
"strings"
"time"
)
type WorkMode int
const (
ModeIPCheck WorkMode = iota
ModeGeoInfo
ModeIPFilter
)
type Config struct {
Mode WorkMode
IPPort int
NoSave bool
CIDRSampleIPNum int
PureMode bool
Runtime struct {
IPSources []string
OutputFile string
Verbose bool
ResolveThreadNum int
WhiteList []string
BlockList []string
PreferLocs []string
PreferPorts []int
PreferOrgs []string
BlockOrgs []string
DryRun bool
OnlyV4 bool
OnlyV6 bool
}
Valid struct {
Enabled bool
IPLimitCount int
HostName string
UserAgent bool
Path string
FileCheck bool
FileURL string
ThreadNum int
MaxRetry int
RetryFactor float64
Timeout float64
CheckKey string
PrintErr bool
PreferColo []string
BlockColo []string
}
RTT struct {
Enabled bool
IPLimitCount int
Interval float64
ThreadNum int
Timeout float64
MaxRTT float64
TestCount int
MaxLoss float64
FastCheck bool
PrintErr bool
}
Speed struct {
Enabled bool
IPLimitCount int
URL string
UserAgent bool
MaxRetry int
RetryFactor float64
Timeout float64
DownloadTime float64
DownloadSpeed int
AvgDownloadSpeed int
FastCheck bool
BetterIPLimit int
RemoveErrIP bool
PrintErr bool
}
}
type GeoConfig struct {
Proxy string
DBAPIURL string
DBASNURL string
DBCityURL string
}
type IPInfo struct {
IP string
Port int
RTT float64
Loss float64
MaxSpeed int
AvgSpeed int
Loc string
Colo string
CountryCity string
Org string
ASN uint
Network string
Hostname string
STTestTag string
}
func newIPInfo(ip string, port int) IPInfo {
return IPInfo{
IP: ip,
Port: port,
RTT: -1,
Loss: 0,
MaxSpeed: -1,
AvgSpeed: -1,
Loc: "None",
Colo: "None",
CountryCity: "NG-NG",
Org: "NG",
Network: "None",
}
}
func (i IPInfo) ipString() string {
ipStr := i.IP
if strings.Contains(ipStr, ":") && !strings.HasPrefix(ipStr, "[") {
ipStr = "[" + ipStr + "]"
}
if i.Hostname != "" {
ipStr = fmt.Sprintf("%s(%s)", i.Hostname, ipStr)
}
return ipStr
}
func (i IPInfo) simpleInfo() string {
return fmt.Sprintf("(%s:%d)", i.ipString(), i.Port)
}
func (i IPInfo) geoInfo() string {
return fmt.Sprintf("%s(%s)", i.CountryCity, i.Org)
}
func (i IPInfo) geoInfoString() string {
return fmt.Sprintf("%s 归属: %s ASN: %d CIDR: %s", i.ipString(), i.geoInfo(), i.ASN, i.Network)
}
func (i IPInfo) rttInfo() string {
return fmt.Sprintf("%s:%d %s_%s %s loss: %s%% rtt: %s ms",
i.ipString(), i.Port, i.Loc, i.Colo, i.geoInfo(), pyFloat(i.Loss), pyFloat(i.RTT))
}
func (i IPInfo) infoString() string {
return " " + i.fileInfoString()
}
func (i IPInfo) fileInfoString() string {
return fmt.Sprintf("%s:%d%s %s_%s %s loss: %s%% rtt: %s ms, 下载速度(max/avg)为: %d/%d kB/s",
i.ipString(), i.Port, i.STTestTag, i.Loc, i.Colo, i.geoInfo(), pyFloat(i.Loss), pyFloat(i.RTT), i.MaxSpeed, i.AvgSpeed)
}
type geoReaders struct {
city *geoDBReader
asn *geoDBReader
}
type geoDBReader struct {
path string
open bool
}
type httpResult struct {
Status int
Header map[string][]string
Body []byte
RemoteAddr net.Addr
}
func durationSeconds(v float64) time.Duration {
return time.Duration(v * float64(time.Second))
}
func pyFloat(v float64) string {
return strconv.FormatFloat(v, 'f', -1, 64)
}