mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-03-10 00:25:57 +08:00
Compare commits
187 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8264138dd8 | ||
|
|
6cb94db59e | ||
|
|
85923cf335 | ||
|
|
60631a958f | ||
|
|
ea46fc5e04 | ||
|
|
9471094d27 | ||
|
|
be4634ee9d | ||
|
|
e5bbd07aea | ||
|
|
445ca36877 | ||
|
|
f6288f4e52 | ||
|
|
cfe30c2f6a | ||
|
|
115bd2af03 | ||
|
|
272eb40d5b | ||
|
|
2c46cfcd0f | ||
|
|
8eea8cdd0e | ||
|
|
f82425bbb6 | ||
|
|
2fa023c7f3 | ||
|
|
ed0a8bbfea | ||
|
|
7301d32cbe | ||
|
|
ab6390a4a4 | ||
|
|
fdbf9ca131 | ||
|
|
49c14f3e0e | ||
|
|
80eadc8df2 | ||
|
|
fbaa312622 | ||
|
|
48012f513a | ||
|
|
28d5d89e85 | ||
|
|
f1a9b5c966 | ||
|
|
4d64abb94d | ||
|
|
71671ebe66 | ||
|
|
83c63e975e | ||
|
|
6f74e60444 | ||
|
|
921bb5ed62 | ||
|
|
337de75d11 | ||
|
|
169af2afe9 | ||
|
|
ccfca867d3 | ||
|
|
897977a11d | ||
|
|
7212110dde | ||
|
|
d651fdeb54 | ||
|
|
d453124943 | ||
|
|
e92badf8be | ||
|
|
01dc5df491 | ||
|
|
b428775cc5 | ||
|
|
5202f73108 | ||
|
|
1bb45af3f1 | ||
|
|
3736d81dda | ||
|
|
a42059737b | ||
|
|
46da45b25f | ||
|
|
acd47ee96d | ||
|
|
698108f453 | ||
|
|
2963b61910 | ||
|
|
9bab2944b1 | ||
|
|
fa5e4f34f0 | ||
|
|
db9d092010 | ||
|
|
180097b044 | ||
|
|
c115249811 | ||
|
|
3b7851f77c | ||
|
|
80c201f160 | ||
|
|
85546abb23 | ||
|
|
1d46334a6b | ||
|
|
afd8736268 | ||
|
|
17ff85954f | ||
|
|
7ece9d6cda | ||
|
|
d67b9bc86d | ||
|
|
73ae874645 | ||
|
|
0441c27cec | ||
|
|
7e5804b7ba | ||
|
|
cee772547b | ||
|
|
1a939f752b | ||
|
|
5b45f400a2 | ||
|
|
3b43b21b83 | ||
|
|
2f284efddd | ||
|
|
f960ce4a4b | ||
|
|
8ae1d495af | ||
|
|
3b957cb1a4 | ||
|
|
faee85edb8 | ||
|
|
b901003dd1 | ||
|
|
873200de80 | ||
|
|
ac29c9666e | ||
|
|
a540789180 | ||
|
|
012865f02d | ||
|
|
74c1744ca6 | ||
|
|
e66d44882e | ||
|
|
0d3af2d5f8 | ||
|
|
70d11e3bc1 | ||
|
|
ec650d3084 | ||
|
|
4038a5b0aa | ||
|
|
1ff4c24c59 | ||
|
|
ffbb161f79 | ||
|
|
3efabb5661 | ||
|
|
e2f23aeb48 | ||
|
|
97bbb8b5e9 | ||
|
|
5d75cb861e | ||
|
|
eed4f4fa0b | ||
|
|
e8537fb0ae | ||
|
|
f1147c5cbf | ||
|
|
8a7b0f12f5 | ||
|
|
6a3504e98c | ||
|
|
78a8f9c6c4 | ||
|
|
aa11024026 | ||
|
|
cf1a01b614 | ||
|
|
b9159db975 | ||
|
|
157b89d88e | ||
|
|
d1c304ff59 | ||
|
|
ceff5971d2 | ||
|
|
32d544184b | ||
|
|
f82471671c | ||
|
|
638273b7e7 | ||
|
|
dc68529244 | ||
|
|
29c927d3cd | ||
|
|
fb190c661d | ||
|
|
9e39be140a | ||
|
|
09a578decf | ||
|
|
8ef6b3b7c2 | ||
|
|
cc6b5dd7a6 | ||
|
|
6c1166fc5e | ||
|
|
f9ac05a072 | ||
|
|
976dd79913 | ||
|
|
c8ef175207 | ||
|
|
31dc7aed3c | ||
|
|
e3a6f80a14 | ||
|
|
38e1d26341 | ||
|
|
166d9abe7c | ||
|
|
f9c310bfb4 | ||
|
|
0d54b65f33 | ||
|
|
9f2e5b5b5e | ||
|
|
7b4f6944be | ||
|
|
00b569d649 | ||
|
|
4b4426c195 | ||
|
|
ff3a6d1d56 | ||
|
|
a78c6e6270 | ||
|
|
6b52fbf5ea | ||
|
|
25fa4b65d8 | ||
|
|
dca761ec72 | ||
|
|
0f5b18b305 | ||
|
|
4e1678edc3 | ||
|
|
65b451ec4d | ||
|
|
72ecee9e26 | ||
|
|
1d9f64a4a2 | ||
|
|
40b22f660a | ||
|
|
12039f4850 | ||
|
|
129deeaf71 | ||
|
|
3de6b38e00 | ||
|
|
8c0e8732cc | ||
|
|
8820c5f982 | ||
|
|
d50c4806a6 | ||
|
|
306ce709c9 | ||
|
|
956a35cab0 | ||
|
|
3d49bb13ed | ||
|
|
3ddd66b3c1 | ||
|
|
9aa64db555 | ||
|
|
9654cb8ea6 | ||
|
|
13bae9c6f8 | ||
|
|
f0fa3e4d0a | ||
|
|
b83734b426 | ||
|
|
c1348df16e | ||
|
|
c52750ad9c | ||
|
|
0e9461f3b7 | ||
|
|
07e20028cc | ||
|
|
4c92eae311 | ||
|
|
efdbc8f08e | ||
|
|
e85a03c651 | ||
|
|
5d00d7c5ff | ||
|
|
92d5216259 | ||
|
|
63e2bc00ee | ||
|
|
5664055c84 | ||
|
|
c6bfd01dd5 | ||
|
|
383f4c979b | ||
|
|
31743a8138 | ||
|
|
479629b84e | ||
|
|
03a1b44e88 | ||
|
|
963dfa68ed | ||
|
|
6417339312 | ||
|
|
edf5dee039 | ||
|
|
12a9fd2ffb | ||
|
|
d73b1374bc | ||
|
|
68899b53fb | ||
|
|
df0b12f018 | ||
|
|
31dbf635a8 | ||
|
|
8e3ee6f2d0 | ||
|
|
4af4d4d3c8 | ||
|
|
7290f04a6b | ||
|
|
9ea310a4d8 | ||
|
|
2dfea884a2 | ||
|
|
12045f96e8 | ||
|
|
fb84c81497 | ||
|
|
51aaa16d79 | ||
|
|
5c67f34e71 |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
dist
|
||||||
|
Releases
|
||||||
|
*.exe
|
||||||
|
*.csv
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"log"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func loadFirstIPOfRangeFromFile() []net.IPAddr {
|
|
||||||
file, err := os.Open("ip.txt")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
firstIPs := make([]net.IPAddr, 0)
|
|
||||||
scanner := bufio.NewScanner(file)
|
|
||||||
scanner.Split(bufio.ScanLines)
|
|
||||||
for scanner.Scan() {
|
|
||||||
IPString := scanner.Text()
|
|
||||||
firstIP, IPRange, err := net.ParseCIDR(IPString)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
firstIP[15]=ipEndWith
|
|
||||||
for IPRange.Contains(firstIP) {
|
|
||||||
firstIPCopy := make([]byte, len(firstIP))
|
|
||||||
copy(firstIPCopy, firstIP)
|
|
||||||
firstIPs = append(firstIPs, net.IPAddr{IP: firstIPCopy})
|
|
||||||
firstIP[14]++
|
|
||||||
if firstIP[14] == 0 {
|
|
||||||
firstIP[13]++
|
|
||||||
if firstIP[13] == 0 {
|
|
||||||
firstIP[12]++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return firstIPs
|
|
||||||
}
|
|
||||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
368
README.md
368
README.md
@@ -1,10 +1,358 @@
|
|||||||
# CloudflareScanner
|
# XIU2/CloudflareSpeedTest
|
||||||
|
|
||||||
本项目可以测试Cloudflare节点接入速度
|
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
||||||
|
[](https://github.com/XIU2/CloudflareSpeedTest/releases/latest)
|
||||||
程序运行完毕后,结果会保存在当前目录的`result.csv`下
|
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
||||||
|
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
||||||
## 注意事项
|
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
||||||
#### 协程数请不要调过1000,否则容易出现较大误差
|
|
||||||
#### 编译选项为 `go build`
|
[国外很多网站](https://github.com/XIU2/CloudflareSpeedTest/discussions/62)都在使用 Cloudflare CDN,但分配给中国访客的 IP 并不友好(高延迟/高丢包/速度慢等)。
|
||||||
#### 您可在release界面下载或编译运行
|
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,所以就有了这个软件。
|
||||||
|
|
||||||
|
**「自选 IP/优选 IP」测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**!好用的话**点个⭐鼓励一下叭~**
|
||||||
|
|
||||||
|
> _分享我的其他开源项目:[**TrackersList.com** - 全网热门 BT Tracker 列表!有效提高 BT 下载速度~](https://github.com/XIU2/TrackersListCollection) <img src="https://img.shields.io/github/stars/XIU2/TrackersListCollection.svg?style=flat-square&label=Star&color=4285dd&logo=github" height="16px" />_
|
||||||
|
> _[一个 **\[油猴脚本\]** 轻松解决「Github」文件下载速度慢的问题!](https://github.com/XIU2/UserScript)(及十几个油猴脚本 <img src="https://img.shields.io/github/stars/XIU2/UserScript.svg?style=flat-square&label=Star&color=4285dd&logo=github" height="16px" />_
|
||||||
|
|
||||||
|
****
|
||||||
|
## 快速使用
|
||||||
|
|
||||||
|
### 下载运行
|
||||||
|
|
||||||
|
1. 下载编译好的可执行文件 [蓝奏云](https://pan.lanzoui.com/b0742hkxe) / [Github](https://github.com/XIU2/CloudflareSpeedTest/releases) 并解压。
|
||||||
|
2. 双击运行 `CloudflareST.exe`文件(Windows),等待测速完成...
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><code><strong>「 点击查看 Linux 下载运行命令示例 」</strong></code></summary>
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
以下命令仅为示例,版本号和文件名请前往 [**Releases**](https://github.com/XIU2/CloudflareSpeedTest/releases) 查看。
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 如果是第一次使用,则建议创建新文件夹(后续更新请跳过该步骤)
|
||||||
|
mkdir CloudflareST
|
||||||
|
|
||||||
|
# 进入文件夹(后续更新,只需要从这里重复下面的下载、解压命令即可)
|
||||||
|
cd CloudflareST
|
||||||
|
|
||||||
|
# 下载 CloudflareST 压缩包(自行根据需求替换 URL 中版本号和文件名)
|
||||||
|
wget -N https://github.com/XIU2/CloudflareSpeedTest/releases/download/v1.5.0/CloudflareST_linux_amd64.tar.gz
|
||||||
|
|
||||||
|
# 解压(不需要删除旧文件,会直接覆盖,自行根据需求替换 文件名)
|
||||||
|
tar -zxf CloudflareST_linux_amd64.tar.gz
|
||||||
|
|
||||||
|
# 赋予执行权限
|
||||||
|
chmod +x CloudflareST
|
||||||
|
|
||||||
|
# 运行
|
||||||
|
./CloudflareST
|
||||||
|
```
|
||||||
|
|
||||||
|
> 如果平**均延迟非常低**(如 0.xx),则说明 CloudflareST **测速时走了代理**,请先关闭代理软件后再测速。
|
||||||
|
> 如果在**路由器**上运行(如 OpenWrt),请先关闭路由器内的代理,否则测速结果会**不准确且无法使用**。
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
> [_**在 Android 手机上运行 CloudflareST 测速的简单教程 ...**_](https://github.com/XIU2/CloudflareSpeedTest/discussions/61)
|
||||||
|
> _**建议测速时避开晚上高峰期(20:00~24:00)**,否则测速结果会与其他时间**相差很大...**_
|
||||||
|
|
||||||
|
### 结果示例
|
||||||
|
|
||||||
|
测速完毕后,默认会显示**最快的 10 个 IP**,示例(我联通白天测速结果):
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
IP 地址 已发送 已接收 丢包率 平均延迟 下载速度 (MB/s)
|
||||||
|
104.27.200.69 4 4 0.00 146.23 28.64
|
||||||
|
172.67.60.78 4 4 0.00 139.82 15.02
|
||||||
|
104.25.140.153 4 4 0.00 146.49 14.90
|
||||||
|
104.27.192.65 4 4 0.00 140.28 14.07
|
||||||
|
172.67.62.214 4 4 0.00 139.29 12.71
|
||||||
|
104.27.207.5 4 4 0.00 145.92 11.95
|
||||||
|
172.67.54.193 4 4 0.00 146.71 11.55
|
||||||
|
104.22.66.8 4 4 0.00 147.42 11.11
|
||||||
|
104.27.197.63 4 4 0.00 131.29 10.26
|
||||||
|
172.67.58.91 4 4 0.00 140.19 9.14
|
||||||
|
...
|
||||||
|
|
||||||
|
# 如果平均延迟非常低(如 0.xx),则说明 CloudflareST 测速时走了代理,请先关闭代理软件后再测速。
|
||||||
|
# 如果在路由器上运行(如 OpenWrt),请先关闭路由器内的代理,否则测速结果会不准确且无法使用。
|
||||||
|
|
||||||
|
# 因为默认下载测速地址的文件大小只有 300MB,如果你速度太快的话,测速结果可能会低于实际速度。
|
||||||
|
# 因为每次测速都是在每个 IP 段中随机 IP,所以每次的测速结果都不可能相同,这是正常的!
|
||||||
|
|
||||||
|
# 软件是先 延迟测速并按从低到高排序后,再从 最低延迟的 IP 开始下载测速的,所以:
|
||||||
|
```
|
||||||
|
|
||||||
|
测速结果第一行就是**既下载速度最快、又平均延迟最低的最快 IP**!至于拿来干嘛?取决于你~
|
||||||
|
|
||||||
|
完整结果保存在当前目录下的 `result.csv` 文件中,用**记事本/表格软件**打开,格式如下:
|
||||||
|
|
||||||
|
```
|
||||||
|
IP 地址, 已发送, 已接收, 丢包率, 平均延迟, 下载速度 (MB/s)
|
||||||
|
104.27.200.69, 4, 4, 0.00, 146.23, 28.64
|
||||||
|
```
|
||||||
|
|
||||||
|
> _大家可以按自己需求,对完整结果**进一步筛选处理**,或者去看一看进阶使用**指定过滤条件**!_
|
||||||
|
|
||||||
|
****
|
||||||
|
## 进阶使用
|
||||||
|
|
||||||
|
直接运行使用的是默认参数,如果想要测速结果更全面、更符合自己的要求,可以自定义参数。
|
||||||
|
|
||||||
|
``` cmd
|
||||||
|
C:\>CloudflareST.exe -h
|
||||||
|
|
||||||
|
CloudflareSpeedTest vX.X.X
|
||||||
|
测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP (IPv4+IPv6)!
|
||||||
|
https://github.com/XIU2/CloudflareSpeedTest
|
||||||
|
|
||||||
|
参数:
|
||||||
|
-n 200
|
||||||
|
测速线程数量;越多测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000)
|
||||||
|
-t 4
|
||||||
|
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
||||||
|
-tp 443
|
||||||
|
指定测速端口;延迟测速/下载测速时使用的端口;(默认 443)
|
||||||
|
-dn 10
|
||||||
|
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10)
|
||||||
|
-dt 10
|
||||||
|
下载测速时间;单个 IP 下载测速最长时间,单位:秒;(默认 10)
|
||||||
|
-url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
|
||||||
|
下载测速地址;用来下载测速的 Cloudflare CDN 文件地址,如地址含有空格请加上引号;
|
||||||
|
-tl 200
|
||||||
|
平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms)
|
||||||
|
-tll 40
|
||||||
|
平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配、过滤被假蔷的 IP;(默认 0 ms)
|
||||||
|
-sl 5
|
||||||
|
下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
|
||||||
|
-p 10
|
||||||
|
显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 10)
|
||||||
|
-f ip.txt
|
||||||
|
IP段数据文件;如路径含有空格请加上引号;支持其他 CDN IP段;(默认 ip.txt)
|
||||||
|
-o result.csv
|
||||||
|
写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
|
||||||
|
-dd
|
||||||
|
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
|
||||||
|
-ipv6
|
||||||
|
IPv6测速模式;确保 IP 段数据文件内只包含 IPv6 IP段,软件不支持同时测速 IPv4+IPv6;(默认 IPv4)
|
||||||
|
-allip
|
||||||
|
测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 IP 段随机测速一个 IP)
|
||||||
|
-v
|
||||||
|
打印程序版本+检查版本更新
|
||||||
|
-h
|
||||||
|
打印帮助说明
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用示例
|
||||||
|
|
||||||
|
Windows 要指定参数需要在 CMD 中运行,或者把参数添加到快捷方式目标中。
|
||||||
|
|
||||||
|
> **注意**:各参数均有**默认值**,使用默认值的参数是可以省略的(**按需选择**),参数**不分前后顺序**。
|
||||||
|
> **提示**:Linux 系统只需要把下面命令中的 `CloudflareST.exe` 改为 `./CloudflareST` 即可。
|
||||||
|
|
||||||
|
#### \# IPv4/IPv6
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 测速 IPv4 时,需要指定 IPv4 数据文件(-f 默认值就是 ip.txt,所以该参数可以省略)
|
||||||
|
CloudflareST.exe -f ip.txt
|
||||||
|
|
||||||
|
# 测速 IPv6 时,需要指定 IPv6 数据文件( ipv6.txt ),需要加上 -ipv6 参数
|
||||||
|
CloudflareST.exe -f ipv6.txt -ipv6
|
||||||
|
```
|
||||||
|
****
|
||||||
|
#### \# 文件相对/绝对路径
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 指定 IPv4 数据文件,不显示结果直接退出,输出结果到文件(-p 值为 0)
|
||||||
|
CloudflareST.exe -f 1.txt -p 0 -dd
|
||||||
|
|
||||||
|
# 指定 IPv4 数据文件,不输出结果到文件,直接显示结果(-p 值为 10 条,-o 值为空但引号不能少)
|
||||||
|
CloudflareST.exe -f 2.txt -o "" -p 10 -dd
|
||||||
|
|
||||||
|
# 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录下,如含空格请加上引号)
|
||||||
|
CloudflareST.exe -f 3.txt -o result.txt -dd
|
||||||
|
|
||||||
|
# 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录内的 abc 文件夹下,如含空格请加上引号)
|
||||||
|
# Linux(CloudflareST 程序所在目录内的 abc 文件夹下)
|
||||||
|
./CloudflareST -f abc/3.txt -o abc/result.txt -dd
|
||||||
|
# Windows(注意是反斜杠)
|
||||||
|
CloudflareST.exe -f abc\3.txt -o abc\result.txt -dd
|
||||||
|
|
||||||
|
# 指定 IPv4 数据文件 及 输出结果到文件(绝对路径,即 C:\abc\ 目录下,如含空格请加上引号)
|
||||||
|
# Linux(/abc/ 目录下)
|
||||||
|
./CloudflareST -f /abc/4.txt -o /abc/result.csv -dd
|
||||||
|
# Windows(注意是反斜杠)
|
||||||
|
CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
|
||||||
|
```
|
||||||
|
****
|
||||||
|
#### \# 自定义下载测速地址
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 地址要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN
|
||||||
|
CloudflareST.exe -url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
|
||||||
|
# 因为默认下载测速地址的文件大小只有 300MB,如果你速度太快的话,测速结果可能会低于实际速度。
|
||||||
|
|
||||||
|
# 注意:如果下载测速地址为 HTTP 协议,记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口)
|
||||||
|
CloudflareST.exe -tp 80 -url http://xxx/xxx
|
||||||
|
```
|
||||||
|
****
|
||||||
|
#### \# 自定义测速条件
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
- 指定 **[平均延迟下限]** 条件(用于过滤**被假蔷的 IP**,这类 IP 都被 TCP 劫持,因此延迟很低只有几十ms)
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 平均延迟下限:40 ms (一般除了移动直连香港外,几乎不存在低于 100ms 的,自行测试适合的下限延迟)
|
||||||
|
# 平均延迟下限和其他的上下限参数一样,都可以单独使用、互相搭配使用!
|
||||||
|
CloudflareST.exe -tll 40
|
||||||
|
```
|
||||||
|
|
||||||
|
- 仅指定 **[平均延迟上限]** 条件
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 平均延迟上限:200 ms,下载速度下限:0 MB/s,数量:10 个(可选)
|
||||||
|
# 即找到平均延迟低于 200 ms 的 IP,然后再按延迟从低到高进行 10 次下载测速
|
||||||
|
CloudflareST.exe -tl 200 -dn 10
|
||||||
|
```
|
||||||
|
|
||||||
|
> 如果没有一个 IP **平均延迟低于 200ms**,那么不会输出任何内容。
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
- 仅指定 **[平均延迟上限]** 条件,且**只延迟测速,不下载测速**
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 平均延迟上限:200 ms,下载速度下限:0 MB/s,数量:不知道多少 个
|
||||||
|
# 即只输出低于 200ms 的 IP,且不再下载测速(因为不再下载测速,所以 -dn 参数就无效了)
|
||||||
|
CloudflareST.exe -tl 200 -dd
|
||||||
|
```
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
- 仅指定 **[下载速度下限]** 条件
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 平均延迟上限:9999 ms,下载速度下限:5 MB/s,数量:10 个(可选)
|
||||||
|
# 即需要找到 10 个平均延迟低于 9999 ms 且下载速度高于 5 MB/s 的 IP 才会停止测速
|
||||||
|
CloudflareST.exe -sl 5 -dn 10
|
||||||
|
```
|
||||||
|
|
||||||
|
> 没有指定平均延迟上限时,如果一直**凑不够**满足条件的 IP 数量,就会**一直测速**下去。
|
||||||
|
> 所以建议**同时指定 [下载速度下限] + [平均延迟上限]**,这样测速到指定延迟上限还没凑够数量,就会终止测速。
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
- 同时指定 **[平均延迟上限] + [下载速度下限]** 条件
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 平均延迟上限、下载速度下限均支持小数(如 -sl 0.5)
|
||||||
|
# 平均延迟上限:200 ms,下载速度下限:5.6 MB/s,数量:10 个(可选)
|
||||||
|
# 即需要找到 10 个平均延迟低于 200 ms 且下载速度高于 5 .6MB/s 的 IP 才会停止测速
|
||||||
|
CloudflareST.exe -tl 200 -sl 5.6 -dn 10
|
||||||
|
```
|
||||||
|
|
||||||
|
> 如果没有一个 IP **平均延迟低于 200ms**,那么不会输出任何内容。
|
||||||
|
> 如果没有一个 IP **下载速度高于 5.6 MB/s**,那么就会**和不指定 [下载速度下限] 条件一样**输出结果。
|
||||||
|
> 所以建议先不指定条件测速一遍,看看平均延迟和下载速度大概在什么范围,避免指定条件**过低/过高**!
|
||||||
|
|
||||||
|
> 因为Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法使用的,所以下载测速是 0.00。
|
||||||
|
> 运行时可以加上 `-sl 0.01`(下载速度下限),过滤掉**回源 IP**(下载测速低于 0.01MB/s 的结果)。
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
****
|
||||||
|
#### \# 单独对一个或多个 IP 测速
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
如果要单独**对一个或多个 IP 进行测速**,只需要把这些 IP 按如下格式写入到任意文本文件中,例如:`1.txt`
|
||||||
|
|
||||||
|
```
|
||||||
|
1.1.1.1
|
||||||
|
1.1.1.200
|
||||||
|
1.0.0.1/24
|
||||||
|
```
|
||||||
|
|
||||||
|
> 单个 IP 的话可以省略 `/32` 子网掩码了(即 `1.1.1.1`等同于 `1.1.1.1/32`)。
|
||||||
|
> 子网掩码 `/24` 指的是这个 IP 最后一段,即 `1.0.0.1~1.0.0.255`。
|
||||||
|
|
||||||
|
|
||||||
|
然后运行 CloudflareST 时加上启动参数 `-f 1.txt` 即可。
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# 先进入 CloudflareST 所在目录,然后运行:
|
||||||
|
# Windows 系统(在 CMD 中运行)
|
||||||
|
CloudflareST.exe -f 1.txt
|
||||||
|
|
||||||
|
# Linux 系统
|
||||||
|
./CloudflareST -f 1.txt
|
||||||
|
|
||||||
|
# 对于 1.0.0.1/24 这样的 IP 段只会随机最后一段(1.0.0.1~255),如果要测速该 IP 段中的所有 IP,请加上 -allip 参数。
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
****
|
||||||
|
#### \# Windows 快捷方式如何使用参数
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
## 右键快捷方式 - 目标
|
||||||
|
# 如果要不输出结果文件,那么请加上 -o " ",引号里的是空格(没有空格会导致该参数被省略)。
|
||||||
|
D:\ABC\CloudflareST\CloudflareST.exe -n 500 -t 4 -dn 20 -dt 5 -o " "
|
||||||
|
|
||||||
|
# 如果文件路径包含引号,则需要把启动参数放在引号外面,记得引号和 - 之间有空格。
|
||||||
|
"D:\Program Files\CloudflareST\CloudflareST.exe" -n 500 -t 4 -dn 20 -dt 5 -o " "
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
****
|
||||||
|
#### \# 一劳永逸加速所有使用 Cloudflare CDN 的网站(不需要再一个个添加域名到 Hosts 了)
|
||||||
|
|
||||||
|
我以前说过,开发该软件项目的目的就是为了通过**改 Hosts 的方式来加速访问使用 Cloudflare CDN 的网站**。
|
||||||
|
|
||||||
|
但就如 [**#8**](https://github.com/XIU2/CloudflareSpeedTest/issues/8) 所说,一个个添加域名到 Hosts 实在**太麻烦**了,于是我就找到了个**一劳永逸**的办法!
|
||||||
|
|
||||||
|
可以看这个 [**还在一个个添加 Hosts?完美本地加速所有使用 Cloudflare CDN 的网站方法来了!**](https://github.com/XIU2/CloudflareSpeedTest/discussions/71)
|
||||||
|
|
||||||
|
****
|
||||||
|
#### \# 自动更新 Hosts
|
||||||
|
|
||||||
|
考虑到很多人获得最快 Cloudflare CDN IP 后,需要替换 Hosts 文件中的 IP。
|
||||||
|
|
||||||
|
可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/42) 获取 **Windows/Linux 自动更新 Hosts 脚本**!
|
||||||
|
|
||||||
|
****
|
||||||
|
## 问题反馈
|
||||||
|
|
||||||
|
如果你遇到什么问题,可以先去 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues) 里看看是否有别人问过了(记得去看下 [**Closed**](https://github.com/XIU2/CloudflareSpeedTest/issues?q=is%3Aissue+is%3Aclosed) 的)。
|
||||||
|
如果没找到类似问题,请新开个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/new) 来告诉我!
|
||||||
|
|
||||||
|
> _有问题请**大胆告诉我**,描述越详细越好(必要时可远程协助),如果不说那我怎么去完善功能或~~修复 BUG~~ 呢?!_
|
||||||
|
|
||||||
|
****
|
||||||
|
## 感谢项目
|
||||||
|
|
||||||
|
* https://github.com/Spedoske/CloudflareScanner
|
||||||
|
|
||||||
|
> _因为该项目已经很长时间没更新了,而我又产生了很多功能需求,所以我临时学了下 Go 语言就上手了(菜)..._
|
||||||
|
> _本软件基于该项目制作,但**已添加大量功能及修复 BUG**,并根据大家的使用反馈积极添加、优化功能(闲)..._
|
||||||
|
|
||||||
|
****
|
||||||
|
## License
|
||||||
|
The GPL-3.0 License.
|
||||||
|
|||||||
7
go.mod
7
go.mod
@@ -1,5 +1,8 @@
|
|||||||
module CloudflareIPScanner
|
module CloudflareSpeedTest
|
||||||
|
|
||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require github.com/cheggaaa/pb/v3 v3.0.4
|
require (
|
||||||
|
github.com/VividCortex/ewma v1.1.1
|
||||||
|
github.com/cheggaaa/pb/v3 v3.0.4
|
||||||
|
)
|
||||||
|
|||||||
17
go.sum
Normal file
17
go.sum
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
|
||||||
|
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
|
||||||
|
github.com/cheggaaa/pb/v3 v3.0.4 h1:QZEPYOj2ix6d5oEg63fbHmpolrnNiwjUsk+h74Yt4bM=
|
||||||
|
github.com/cheggaaa/pb/v3 v3.0.4/go.mod h1:7rgWxLrAUcFMkvJuv09+DYi7mMUYi8nO9iOWcvGJPfw=
|
||||||
|
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||||
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
|
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
||||||
|
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
|
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
|
||||||
|
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
||||||
|
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
||||||
|
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
|
||||||
|
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
20
ip.txt
20
ip.txt
@@ -1,3 +1,7 @@
|
|||||||
|
1.1.1.0/24
|
||||||
|
1.0.0.0/24
|
||||||
|
1.1.1.1/32
|
||||||
|
1.0.0.1/32
|
||||||
173.245.48.0/20
|
173.245.48.0/20
|
||||||
103.21.244.0/22
|
103.21.244.0/22
|
||||||
103.22.200.0/22
|
103.22.200.0/22
|
||||||
@@ -9,6 +13,18 @@
|
|||||||
197.234.240.0/22
|
197.234.240.0/22
|
||||||
198.41.128.0/17
|
198.41.128.0/17
|
||||||
162.158.0.0/15
|
162.158.0.0/15
|
||||||
104.16.0.0/12
|
104.16.0.0/13
|
||||||
172.64.0.0/13
|
104.24.0.0/14
|
||||||
|
172.64.0.0/17
|
||||||
|
172.64.128.0/18
|
||||||
|
172.64.192.0/19
|
||||||
|
172.64.224.0/22
|
||||||
|
172.64.229.0/24
|
||||||
|
172.64.230.0/23
|
||||||
|
172.64.232.0/21
|
||||||
|
172.64.240.0/21
|
||||||
|
172.64.248.0/21
|
||||||
|
172.65.0.0/16
|
||||||
|
172.66.0.0/16
|
||||||
|
172.67.0.0/16
|
||||||
131.0.72.0/22
|
131.0.72.0/22
|
||||||
90
ipv6.txt
Normal file
90
ipv6.txt
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
2606:4700::/32
|
||||||
|
2606:4700::6810:0/112
|
||||||
|
2606:4700:10::/96
|
||||||
|
2606:4700:10::6814:0/112
|
||||||
|
2606:4700:10::ac43:0/112
|
||||||
|
2606:4700:130::/48
|
||||||
|
2606:4700:130:436c::/64
|
||||||
|
2606:4700:130:436c:6f75::/80
|
||||||
|
2606:4700:130:436c:6f75:6466::/96
|
||||||
|
2606:4700:130:436c:6f75:6466:6c61:0/112
|
||||||
|
2606:4700:3000::/48
|
||||||
|
2606:4700:3001::/48
|
||||||
|
2606:4700:3002::/48
|
||||||
|
2606:4700:3003::/48
|
||||||
|
2606:4700:3004::/48
|
||||||
|
2606:4700:3005::/48
|
||||||
|
2606:4700:3006::/48
|
||||||
|
2606:4700:3007::/48
|
||||||
|
2606:4700:3008::/48
|
||||||
|
2606:4700:3009::/48
|
||||||
|
2606:4700:3010::/48
|
||||||
|
2606:4700:3011::/48
|
||||||
|
2606:4700:3012::/48
|
||||||
|
2606:4700:3013::/48
|
||||||
|
2606:4700:3014::/48
|
||||||
|
2606:4700:3015::/48
|
||||||
|
2606:4700:3016::/48
|
||||||
|
2606:4700:3017::/48
|
||||||
|
2606:4700:3018::/48
|
||||||
|
2606:4700:3019::/48
|
||||||
|
2606:4700:3020::/48
|
||||||
|
2606:4700:3021::/48
|
||||||
|
2606:4700:3022::/48
|
||||||
|
2606:4700:3023::/48
|
||||||
|
2606:4700:3024::/48
|
||||||
|
2606:4700:3025::/48
|
||||||
|
2606:4700:3026::/48
|
||||||
|
2606:4700:3027::/48
|
||||||
|
2606:4700:3028::/48
|
||||||
|
2606:4700:3029::/48
|
||||||
|
2606:4700:3030::/48
|
||||||
|
2606:4700:3031::/48
|
||||||
|
2606:4700:3032::/48
|
||||||
|
2606:4700:3033::/48
|
||||||
|
2606:4700:3034::/48
|
||||||
|
2606:4700:3035::/48
|
||||||
|
2606:4700:3036::/48
|
||||||
|
2606:4700:3037::/48
|
||||||
|
2606:4700:3038::/48
|
||||||
|
2606:4700:3039::/48
|
||||||
|
2606:4700:3000::/96
|
||||||
|
2606:4700:3001::/96
|
||||||
|
2606:4700:3002::/96
|
||||||
|
2606:4700:3003::/96
|
||||||
|
2606:4700:3004::/96
|
||||||
|
2606:4700:3005::/96
|
||||||
|
2606:4700:3006::/96
|
||||||
|
2606:4700:3007::/96
|
||||||
|
2606:4700:3008::/96
|
||||||
|
2606:4700:3009::/96
|
||||||
|
2606:4700:3010::/96
|
||||||
|
2606:4700:3011::/96
|
||||||
|
2606:4700:3012::/96
|
||||||
|
2606:4700:3013::/96
|
||||||
|
2606:4700:3014::/96
|
||||||
|
2606:4700:3015::/96
|
||||||
|
2606:4700:3016::/96
|
||||||
|
2606:4700:3017::/96
|
||||||
|
2606:4700:3018::/96
|
||||||
|
2606:4700:3019::/96
|
||||||
|
2606:4700:3020::/96
|
||||||
|
2606:4700:3021::/96
|
||||||
|
2606:4700:3022::/96
|
||||||
|
2606:4700:3023::/96
|
||||||
|
2606:4700:3024::/96
|
||||||
|
2606:4700:3025::/96
|
||||||
|
2606:4700:3026::/96
|
||||||
|
2606:4700:3027::/96
|
||||||
|
2606:4700:3028::/96
|
||||||
|
2606:4700:3029::/96
|
||||||
|
2606:4700:3030::/96
|
||||||
|
2606:4700:3031::/96
|
||||||
|
2606:4700:3032::/96
|
||||||
|
2606:4700:3033::/96
|
||||||
|
2606:4700:3034::/96
|
||||||
|
2606:4700:3035::/96
|
||||||
|
2606:4700:3036::/96
|
||||||
|
2606:4700:3037::/96
|
||||||
|
2606:4700:3038::/96
|
||||||
|
2606:4700:3039::/96
|
||||||
230
main.go
230
main.go
@@ -1,79 +1,151 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cheggaaa/pb/v3"
|
"io/ioutil"
|
||||||
"log"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"runtime"
|
||||||
)
|
"time"
|
||||||
|
|
||||||
func ExportCsv(filePath string, data [][]string) {
|
"CloudflareSpeedTest/task"
|
||||||
fp, err := os.Create(filePath)
|
"CloudflareSpeedTest/utils"
|
||||||
if err != nil {
|
)
|
||||||
log.Fatalf("创建文件["+filePath+"]句柄失败,%v", err)
|
|
||||||
return
|
var (
|
||||||
}
|
version, versionNew string
|
||||||
defer fp.Close()
|
)
|
||||||
w := csv.NewWriter(fp) //创建一个新的写入文件流
|
|
||||||
w.WriteAll(data)
|
func init() {
|
||||||
w.Flush()
|
var printVersion bool
|
||||||
}
|
var help = `
|
||||||
|
CloudflareSpeedTest ` + version + `
|
||||||
var pingTime int
|
测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP (IPv4+IPv6)!
|
||||||
var pingRoutine int
|
https://github.com/XIU2/CloudflareSpeedTest
|
||||||
const ipEndWith uint8 = 1
|
|
||||||
type progressEvent int
|
参数:
|
||||||
const (
|
-n 200
|
||||||
NoAvailableIPFound progressEvent = iota
|
测速线程数量;越多测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000)
|
||||||
AvailableIPFound
|
-t 4
|
||||||
NormalPing
|
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
||||||
)
|
-tp 443
|
||||||
|
指定测速端口;延迟测速/下载测速时使用的端口;(默认 443)
|
||||||
func handleProgressGenerator(pb *pb.ProgressBar)func (e progressEvent){
|
-dn 10
|
||||||
return func(e progressEvent) {
|
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10)
|
||||||
switch e {
|
-dt 10
|
||||||
case NoAvailableIPFound:
|
下载测速时间;单个 IP 下载测速最长时间,单位:秒;(默认 10)
|
||||||
pb.Add(pingTime)
|
-url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
|
||||||
case AvailableIPFound:
|
下载测速地址;用来下载测速的 Cloudflare CDN 文件地址,如地址含有空格请加上引号;
|
||||||
pb.Add(failTime)
|
-tl 200
|
||||||
case NormalPing:
|
平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms)
|
||||||
pb.Increment()
|
-tll 40
|
||||||
}
|
平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配、过滤被假蔷的 IP;(默认 0 ms)
|
||||||
}
|
-sl 5
|
||||||
}
|
下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
|
||||||
|
-p 10
|
||||||
func handleUserInput(){
|
显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 10)
|
||||||
fmt.Println("请输入扫描协程数(数字越大越快,默认100):")
|
-f ip.txt
|
||||||
fmt.Scanln(&pingRoutine)
|
IP段数据文件;如路径含有空格请加上引号;支持其他 CDN IP段;(默认 ip.txt)
|
||||||
if pingRoutine<=0{
|
-o result.csv
|
||||||
pingRoutine=100
|
写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
|
||||||
}
|
-dd
|
||||||
fmt.Println("请输入tcping次数(默认10):")
|
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
|
||||||
fmt.Scanln(&pingTime)
|
-ipv6
|
||||||
if pingTime<=0{
|
IPv6测速模式;确保 IP 段数据文件内只包含 IPv6 IP段,软件不支持同时测速 IPv4+IPv6;(默认 IPv4)
|
||||||
pingTime=10
|
-allip
|
||||||
}
|
测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 IP 段随机测速一个 IP)
|
||||||
}
|
-v
|
||||||
|
打印程序版本+检查版本更新
|
||||||
func main(){
|
-h
|
||||||
handleUserInput()
|
打印帮助说明
|
||||||
ips:=loadFirstIPOfRangeFromFile()
|
`
|
||||||
pingCount:=len(ips)*pingTime
|
var minDelay, maxDelay, downloadTime int
|
||||||
bar := pb.StartNew(pingCount)
|
flag.IntVar(&task.Routines, "n", 200, "测速线程数量")
|
||||||
var wg sync.WaitGroup
|
flag.IntVar(&task.PingTimes, "t", 4, "延迟测速次数")
|
||||||
var mu sync.Mutex
|
flag.IntVar(&task.TCPPort, "tp", 443, "指定测速端口")
|
||||||
var data = make([][]string,0)
|
flag.IntVar(&maxDelay, "tl", 9999, "平均延迟上限")
|
||||||
data = append(data,[]string{"IP Address","Ping received","Ping time"})
|
flag.IntVar(&minDelay, "tll", 0, "平均延迟下限")
|
||||||
control := make(chan bool,pingRoutine)
|
flag.IntVar(&downloadTime, "dt", 10, "下载测速时间")
|
||||||
for _,ip :=range ips{
|
flag.IntVar(&task.TestCount, "dn", 10, "下载测速数量")
|
||||||
wg.Add(1)
|
flag.StringVar(&task.URL, "url", "https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png", "下载测速地址")
|
||||||
control<-false
|
flag.BoolVar(&task.Disable, "dd", false, "禁用下载测速")
|
||||||
handleProgress:=handleProgressGenerator(bar)
|
flag.BoolVar(&task.IPv6, "ipv6", false, "启用IPv6")
|
||||||
go tcpingGoroutine(&wg,&mu,ip,pingTime, &data,control,handleProgress)
|
flag.BoolVar(&task.TestAll, "allip", false, "测速全部 IP")
|
||||||
}
|
flag.StringVar(&task.IPFile, "f", "ip.txt", "IP 数据文件")
|
||||||
wg.Wait()
|
flag.Float64Var(&task.MinSpeed, "sl", 0, "下载速度下限")
|
||||||
bar.Finish()
|
flag.IntVar(&utils.PrintNum, "p", 10, "显示结果数量")
|
||||||
ExportCsv("./result.csv",data)
|
flag.StringVar(&utils.Output, "o", "result.csv", "输出结果文件")
|
||||||
}
|
flag.BoolVar(&printVersion, "v", false, "打印程序版本")
|
||||||
|
flag.Usage = func() { fmt.Print(help) }
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if task.MinSpeed > 0 && time.Duration(maxDelay)*time.Millisecond == utils.InputMaxDelay {
|
||||||
|
fmt.Println("[小提示] 在使用 [-sl] 参数时,建议搭配 [-tl] 参数,以避免因凑不够 [-dn] 数量而一直测速...")
|
||||||
|
}
|
||||||
|
utils.InputMaxDelay = time.Duration(maxDelay) * time.Millisecond
|
||||||
|
utils.InputMinDelay = time.Duration(minDelay) * time.Millisecond
|
||||||
|
task.Timeout = time.Duration(downloadTime) * time.Second
|
||||||
|
|
||||||
|
if printVersion {
|
||||||
|
println(version)
|
||||||
|
fmt.Println("检查版本更新中...")
|
||||||
|
checkUpdate()
|
||||||
|
if versionNew != "" {
|
||||||
|
fmt.Printf("*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***", versionNew)
|
||||||
|
} else {
|
||||||
|
fmt.Println("当前为最新版本 [" + version + "]!")
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
go checkUpdate() // 检查版本更新
|
||||||
|
task.InitRandSeed() // 置随机数种子
|
||||||
|
|
||||||
|
fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version)
|
||||||
|
|
||||||
|
// 开始延迟测速
|
||||||
|
pingData := task.NewPing().Run().FilterDelay()
|
||||||
|
// 开始下载测速
|
||||||
|
speedData := task.TestDownloadSpeed(pingData)
|
||||||
|
utils.ExportCsv(speedData)
|
||||||
|
speedData.Print(task.IPv6)
|
||||||
|
|
||||||
|
if versionNew != "" {
|
||||||
|
fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew)
|
||||||
|
}
|
||||||
|
endPrint()
|
||||||
|
}
|
||||||
|
|
||||||
|
func endPrint() {
|
||||||
|
if utils.NoPrintResult() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
|
||||||
|
fmt.Printf("按下 回车键 或 Ctrl+C 退出。")
|
||||||
|
var pause int
|
||||||
|
fmt.Scanln(&pause)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查更新
|
||||||
|
func checkUpdate() {
|
||||||
|
timeout := 10 * time.Second
|
||||||
|
client := http.Client{Timeout: timeout}
|
||||||
|
res, err := client.Get("https://api.xiu2.xyz/ver/cloudflarespeedtest.txt")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 读取资源数据 body: []byte
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 关闭资源流
|
||||||
|
defer res.Body.Close()
|
||||||
|
if string(body) != version {
|
||||||
|
versionNew = string(body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
155
task/download.go
Normal file
155
task/download.go
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"CloudflareSpeedTest/utils"
|
||||||
|
|
||||||
|
"github.com/VividCortex/ewma"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
bufferSize = 1024
|
||||||
|
defaultURL = "https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png"
|
||||||
|
defaultTimeout = 10 * time.Second
|
||||||
|
defaultDisableDownload = false
|
||||||
|
defaultTestNum = 10
|
||||||
|
defaultMinSpeed float64 = 0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// download test url
|
||||||
|
URL = defaultURL
|
||||||
|
// download timeout
|
||||||
|
Timeout = defaultTimeout
|
||||||
|
// disable download
|
||||||
|
Disable = defaultDisableDownload
|
||||||
|
|
||||||
|
TestCount = defaultTestNum
|
||||||
|
MinSpeed = defaultMinSpeed
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkDownloadDefault() {
|
||||||
|
if URL == "" {
|
||||||
|
URL = defaultURL
|
||||||
|
}
|
||||||
|
if Timeout <= 0 {
|
||||||
|
Timeout = defaultTimeout
|
||||||
|
}
|
||||||
|
if TestCount <= 0 {
|
||||||
|
TestCount = defaultTestNum
|
||||||
|
}
|
||||||
|
if MinSpeed <= 0.0 {
|
||||||
|
MinSpeed = defaultMinSpeed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSet) {
|
||||||
|
checkDownloadDefault()
|
||||||
|
if Disable {
|
||||||
|
return utils.DownloadSpeedSet(ipSet)
|
||||||
|
}
|
||||||
|
if len(ipSet) <= 0 { // IP数组长度(IP数量) 大于 0 时才会继续下载测速
|
||||||
|
fmt.Println("\n[信息] 延迟测速结果 IP 数量为 0,跳过下载测速。")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
testNum := TestCount
|
||||||
|
if len(ipSet) < TestCount || MinSpeed > 0 { // 如果IP数组长度(IP数量) 小于下载测速数量(-dn),则次数修正为IP数
|
||||||
|
testNum = len(ipSet)
|
||||||
|
}
|
||||||
|
if testNum < TestCount {
|
||||||
|
TestCount = testNum
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s,下载测速数量:%d,下载测速队列:%d):\n", MinSpeed, TestCount, testNum)
|
||||||
|
bar := utils.NewBar(TestCount)
|
||||||
|
for i := 0; i < testNum; i++ {
|
||||||
|
speed := downloadHandler(ipSet[i].IP)
|
||||||
|
ipSet[i].DownloadSpeed = speed
|
||||||
|
// 在每个 IP 下载测速后,以 [下载速度下限] 条件过滤结果
|
||||||
|
if speed >= MinSpeed*1024*1024 {
|
||||||
|
bar.Grow(1)
|
||||||
|
speedSet = append(speedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中
|
||||||
|
if len(speedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn),就跳出循环
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bar.Done()
|
||||||
|
if len(speedSet) == 0 { // 没有符合速度限制的数据,返回所有测试数据
|
||||||
|
speedSet = utils.DownloadSpeedSet(ipSet)
|
||||||
|
}
|
||||||
|
// 按速度排序
|
||||||
|
sort.Sort(speedSet)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDialContext(ip *net.IPAddr) func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
|
fakeSourceAddr := ip.String() + ":" + fmt.Sprintf("%d", TCPPort)
|
||||||
|
if IPv6 { // IPv6 需要加上 []
|
||||||
|
fakeSourceAddr = "[" + ip.String() + "]:" + fmt.Sprintf("%d", TCPPort)
|
||||||
|
}
|
||||||
|
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
|
return (&net.Dialer{}).DialContext(ctx, network, fakeSourceAddr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// return download Speed
|
||||||
|
func downloadHandler(ip *net.IPAddr) float64 {
|
||||||
|
client := &http.Client{
|
||||||
|
Transport: &http.Transport{DialContext: getDialContext(ip)},
|
||||||
|
Timeout: Timeout,
|
||||||
|
}
|
||||||
|
response, err := client.Get(URL)
|
||||||
|
if err != nil {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
|
if response.StatusCode != 200 {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
timeStart := time.Now()
|
||||||
|
timeEnd := timeStart.Add(Timeout)
|
||||||
|
|
||||||
|
contentLength := response.ContentLength
|
||||||
|
buffer := make([]byte, bufferSize)
|
||||||
|
|
||||||
|
var (
|
||||||
|
contentRead int64 = 0
|
||||||
|
timeSlice = Timeout / 100
|
||||||
|
timeCounter = 1
|
||||||
|
lastContentRead int64 = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
var nextTime = timeStart.Add(timeSlice * time.Duration(timeCounter))
|
||||||
|
e := ewma.NewMovingAverage()
|
||||||
|
|
||||||
|
for contentLength != contentRead {
|
||||||
|
currentTime := time.Now()
|
||||||
|
if currentTime.After(nextTime) {
|
||||||
|
timeCounter++
|
||||||
|
nextTime = timeStart.Add(timeSlice * time.Duration(timeCounter))
|
||||||
|
e.Add(float64(contentRead - lastContentRead))
|
||||||
|
lastContentRead = contentRead
|
||||||
|
}
|
||||||
|
if currentTime.After(timeEnd) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
bufferRead, err := response.Body.Read(buffer)
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
e.Add(float64(contentRead-lastContentRead) / (float64(nextTime.Sub(currentTime)) / float64(timeSlice)))
|
||||||
|
}
|
||||||
|
contentRead += int64(bufferRead)
|
||||||
|
}
|
||||||
|
return e.Value() / (Timeout.Seconds() / 120)
|
||||||
|
|
||||||
|
}
|
||||||
159
task/ip.go
Normal file
159
task/ip.go
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const defaultInputFile = "ip.txt"
|
||||||
|
|
||||||
|
var (
|
||||||
|
// IPv6 IP version is 6
|
||||||
|
IPv6 = false
|
||||||
|
// TestAll test all ip
|
||||||
|
TestAll = false
|
||||||
|
// IPFile is the filename of IP Rangs
|
||||||
|
IPFile = defaultInputFile
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitRandSeed() {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
|
func randIPEndWith(num byte) byte {
|
||||||
|
return byte(rand.Intn(int(num)))
|
||||||
|
}
|
||||||
|
|
||||||
|
type IPRanges struct {
|
||||||
|
ips []*net.IPAddr
|
||||||
|
mask string
|
||||||
|
firstIP net.IP
|
||||||
|
ipNet *net.IPNet
|
||||||
|
}
|
||||||
|
|
||||||
|
func newIPRanges() *IPRanges {
|
||||||
|
return &IPRanges{
|
||||||
|
ips: make([]*net.IPAddr, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *IPRanges) fixIP(ip string) string {
|
||||||
|
// 如果不含有 '/' 则代表不是 IP 段,而是一个单独的 IP,因此需要加上 /32 /128 子网掩码
|
||||||
|
if i := strings.IndexByte(ip, '/'); i < 0 {
|
||||||
|
r.mask = "/32"
|
||||||
|
if IPv6 {
|
||||||
|
r.mask = "/128"
|
||||||
|
}
|
||||||
|
ip += r.mask
|
||||||
|
} else {
|
||||||
|
r.mask = ip[i:]
|
||||||
|
}
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *IPRanges) parseCIDR(ip string) {
|
||||||
|
var err error
|
||||||
|
if r.firstIP, r.ipNet, err = net.ParseCIDR(r.fixIP(ip)); err != nil {
|
||||||
|
log.Fatalln("ParseCIDR err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *IPRanges) appendIPv4(d byte) {
|
||||||
|
r.appendIP(net.IPv4(r.firstIP[12], r.firstIP[13], r.firstIP[14], d))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *IPRanges) appendIP(ip net.IP) {
|
||||||
|
r.ips = append(r.ips, &net.IPAddr{IP: ip})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回第四段 ip 的最小值及可用数目
|
||||||
|
func (r *IPRanges) getIPRange() (minIP, hosts byte) {
|
||||||
|
minIP = r.firstIP[15] & r.ipNet.Mask[3] // IP 第四段最小值
|
||||||
|
|
||||||
|
// 根据子网掩码获取主机数量
|
||||||
|
m := net.IPv4Mask(255, 255, 255, 255)
|
||||||
|
for i, v := range r.ipNet.Mask {
|
||||||
|
m[i] ^= v
|
||||||
|
}
|
||||||
|
total, _ := strconv.ParseInt(m.String(), 16, 32) // 总可用 IP 数
|
||||||
|
if total > 255 { // 矫正 第四段 可用 IP 数
|
||||||
|
hosts = 255
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if total == 0 {
|
||||||
|
hosts = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hosts = byte(total)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *IPRanges) chooseIPv4() {
|
||||||
|
minIP, hosts := r.getIPRange()
|
||||||
|
for r.ipNet.Contains(r.firstIP) {
|
||||||
|
if TestAll { // 如果是测速全部 IP
|
||||||
|
for i := 0; i <= int(hosts); i++ { // 遍历 IP 最后一段最小值到最大值
|
||||||
|
r.appendIPv4(byte(i) + minIP)
|
||||||
|
}
|
||||||
|
} else { // 随机 IP 的最后一段 0.0.0.X
|
||||||
|
r.appendIPv4(minIP + randIPEndWith(hosts))
|
||||||
|
}
|
||||||
|
r.firstIP[14]++ // 0.0.(X+1).X
|
||||||
|
if r.firstIP[14] == 0 {
|
||||||
|
r.firstIP[13]++ // 0.(X+1).X.X
|
||||||
|
if r.firstIP[13] == 0 {
|
||||||
|
r.firstIP[12]++ // (X+1).X.X.X
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *IPRanges) chooseIPv6() {
|
||||||
|
var tempIP uint8
|
||||||
|
for r.ipNet.Contains(r.firstIP) {
|
||||||
|
//fmt.Println(firstIP)
|
||||||
|
//fmt.Println(firstIP[0], firstIP[1], firstIP[2], firstIP[3], firstIP[4], firstIP[5], firstIP[6], firstIP[7], firstIP[8], firstIP[9], firstIP[10], firstIP[11], firstIP[12], firstIP[13], firstIP[14], firstIP[15])
|
||||||
|
if r.mask != "/128" {
|
||||||
|
r.firstIP[15] = randIPEndWith(255) // 随机 IP 的最后一段
|
||||||
|
r.firstIP[14] = randIPEndWith(255) // 随机 IP 的最后一段
|
||||||
|
}
|
||||||
|
targetIP := make([]byte, len(r.firstIP))
|
||||||
|
copy(targetIP, r.firstIP)
|
||||||
|
r.appendIP(targetIP)
|
||||||
|
for i := 13; i >= 0; i-- {
|
||||||
|
tempIP = r.firstIP[i]
|
||||||
|
r.firstIP[i] += randIPEndWith(255)
|
||||||
|
if r.firstIP[i] >= tempIP {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadIPRanges() []*net.IPAddr {
|
||||||
|
if IPFile == "" {
|
||||||
|
IPFile = defaultInputFile
|
||||||
|
}
|
||||||
|
file, err := os.Open(IPFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
ranges := newIPRanges()
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
ranges.parseCIDR(scanner.Text())
|
||||||
|
if IPv6 {
|
||||||
|
ranges.chooseIPv6()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ranges.chooseIPv4()
|
||||||
|
}
|
||||||
|
return ranges.ips
|
||||||
|
}
|
||||||
137
task/tcping.go
Normal file
137
task/tcping.go
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"sort"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"CloudflareSpeedTest/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
tcpConnectTimeout = time.Second * 1
|
||||||
|
maxRoutine = 1000
|
||||||
|
defaultRoutines = 200
|
||||||
|
defaultPort = 443
|
||||||
|
defaultPingTimes = 4
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Routines = defaultRoutines
|
||||||
|
TCPPort int = defaultPort
|
||||||
|
PingTimes int = defaultPingTimes
|
||||||
|
)
|
||||||
|
|
||||||
|
type Ping struct {
|
||||||
|
wg *sync.WaitGroup
|
||||||
|
m *sync.Mutex
|
||||||
|
ips []*net.IPAddr
|
||||||
|
csv utils.PingDelaySet
|
||||||
|
control chan bool
|
||||||
|
bar *utils.Bar
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkPingDefault() {
|
||||||
|
if Routines <= 0 {
|
||||||
|
Routines = defaultRoutines
|
||||||
|
}
|
||||||
|
if TCPPort <= 0 || TCPPort >= 65535 {
|
||||||
|
TCPPort = defaultPort
|
||||||
|
}
|
||||||
|
if PingTimes <= 0 {
|
||||||
|
PingTimes = defaultPingTimes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPing() *Ping {
|
||||||
|
checkPingDefault()
|
||||||
|
ips := loadIPRanges()
|
||||||
|
return &Ping{
|
||||||
|
wg: &sync.WaitGroup{},
|
||||||
|
m: &sync.Mutex{},
|
||||||
|
ips: ips,
|
||||||
|
csv: make(utils.PingDelaySet, 0),
|
||||||
|
control: make(chan bool, Routines),
|
||||||
|
bar: utils.NewBar(len(ips)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Ping) Run() utils.PingDelaySet {
|
||||||
|
if len(p.ips) == 0 {
|
||||||
|
return p.csv
|
||||||
|
}
|
||||||
|
ipVersion := "IPv4"
|
||||||
|
if IPv6 { // IPv6 模式判断
|
||||||
|
ipVersion = "IPv6"
|
||||||
|
}
|
||||||
|
fmt.Printf("开始延迟测速(模式:TCP %s,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", ipVersion, TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
|
||||||
|
for _, ip := range p.ips {
|
||||||
|
p.wg.Add(1)
|
||||||
|
p.control <- false
|
||||||
|
go p.start(ip)
|
||||||
|
}
|
||||||
|
p.wg.Wait()
|
||||||
|
p.bar.Done()
|
||||||
|
sort.Sort(p.csv)
|
||||||
|
return p.csv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Ping) start(ip *net.IPAddr) {
|
||||||
|
defer p.wg.Done()
|
||||||
|
p.tcpingHandler(ip)
|
||||||
|
<-p.control
|
||||||
|
}
|
||||||
|
|
||||||
|
//bool connectionSucceed float32 time
|
||||||
|
func (p *Ping) tcping(ip *net.IPAddr) (bool, time.Duration) {
|
||||||
|
startTime := time.Now()
|
||||||
|
fullAddress := fmt.Sprintf("%s:%d", ip.String(), TCPPort)
|
||||||
|
//fmt.Println(ip.String())
|
||||||
|
if IPv6 { // IPv6 需要加上 []
|
||||||
|
fullAddress = fmt.Sprintf("[%s]:%d", ip.String(), TCPPort)
|
||||||
|
}
|
||||||
|
conn, err := net.DialTimeout("tcp", fullAddress, tcpConnectTimeout)
|
||||||
|
if err != nil {
|
||||||
|
return false, 0
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
duration := time.Since(startTime)
|
||||||
|
return true, duration
|
||||||
|
}
|
||||||
|
|
||||||
|
//pingReceived pingTotalTime
|
||||||
|
func (p *Ping) checkConnection(ip *net.IPAddr) (recv int, totalDelay time.Duration) {
|
||||||
|
for i := 0; i < PingTimes; i++ {
|
||||||
|
if ok, delay := p.tcping(ip); ok {
|
||||||
|
recv++
|
||||||
|
totalDelay += delay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Ping) appendIPData(data *utils.PingData) {
|
||||||
|
p.m.Lock()
|
||||||
|
defer p.m.Unlock()
|
||||||
|
p.csv = append(p.csv, utils.CloudflareIPData{
|
||||||
|
PingData: data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle tcping
|
||||||
|
func (p *Ping) tcpingHandler(ip *net.IPAddr) {
|
||||||
|
recv, totalDlay := p.checkConnection(ip)
|
||||||
|
p.bar.Grow(1)
|
||||||
|
if recv == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data := &utils.PingData{
|
||||||
|
IP: ip,
|
||||||
|
Sended: PingTimes,
|
||||||
|
Received: recv,
|
||||||
|
Delay: totalDlay / time.Duration(recv),
|
||||||
|
}
|
||||||
|
p.appendIPData(data)
|
||||||
|
}
|
||||||
87
tcping.go
87
tcping.go
@@ -1,87 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net"
|
|
||||||
"strconv"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const defaultTcpPort = 443
|
|
||||||
const tcpConnectTimeout = time.Second * 1
|
|
||||||
const failTime = 4
|
|
||||||
|
|
||||||
//bool connectionSucceed float64 time
|
|
||||||
func tcping(ip net.IPAddr) (bool, float64) {
|
|
||||||
startTime := time.Now()
|
|
||||||
conn, err := net.DialTimeout("tcp", ip.String()+":"+strconv.Itoa(defaultTcpPort), tcpConnectTimeout)
|
|
||||||
if err != nil {
|
|
||||||
return false, 0
|
|
||||||
} else {
|
|
||||||
var endTime = time.Since(startTime)
|
|
||||||
var duration = float64(endTime.Microseconds()) / 1000.0
|
|
||||||
_ = conn.Close()
|
|
||||||
return true, duration
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//pingReceived pingTotalTime
|
|
||||||
func checkConnection(ip net.IPAddr) (int, float64) {
|
|
||||||
pingRecv := 0
|
|
||||||
pingTime := 0.0
|
|
||||||
for i := 1; i <= failTime; i++ {
|
|
||||||
pingSucceed, pingTimeCurrent := tcping(ip)
|
|
||||||
if pingSucceed {
|
|
||||||
pingRecv++
|
|
||||||
pingTime += pingTimeCurrent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pingRecv, pingTime
|
|
||||||
}
|
|
||||||
|
|
||||||
//return Success packetRecv averagePingTime specificIPAddr
|
|
||||||
func tcpingHandler(ip net.IPAddr, pingCount int, progressHandler func(e progressEvent)) (bool, int, float64, net.IPAddr) {
|
|
||||||
ipCanConnect := false
|
|
||||||
pingRecv := 0
|
|
||||||
pingTime := 0.0
|
|
||||||
for !ipCanConnect {
|
|
||||||
pingRecvCurrent, pingTimeCurrent := checkConnection(ip)
|
|
||||||
if pingRecvCurrent != 0 {
|
|
||||||
ipCanConnect = true
|
|
||||||
pingRecv = pingRecvCurrent
|
|
||||||
pingTime = pingTimeCurrent
|
|
||||||
} else {
|
|
||||||
ip.IP[15]++
|
|
||||||
if ip.IP[15] == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ipCanConnect {
|
|
||||||
progressHandler(AvailableIPFound)
|
|
||||||
for i := failTime; i < pingCount; i++ {
|
|
||||||
pingSuccess, pingTimeCurrent := tcping(ip)
|
|
||||||
progressHandler(NormalPing)
|
|
||||||
if pingSuccess {
|
|
||||||
pingRecv++
|
|
||||||
pingTime += pingTimeCurrent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true, pingRecv, pingTime / float64(pingRecv), ip
|
|
||||||
} else {
|
|
||||||
progressHandler(NoAvailableIPFound)
|
|
||||||
return false, 0, 0, net.IPAddr{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func tcpingGoroutine(wg *sync.WaitGroup, mutex *sync.Mutex, ip net.IPAddr, pingCount int, csv *[][]string, control chan bool, progressHandler func(e progressEvent)) {
|
|
||||||
defer wg.Done()
|
|
||||||
success, pingRecv, pingTimeAvg, currentIP := tcpingHandler(ip, pingCount, progressHandler)
|
|
||||||
if success {
|
|
||||||
mutex.Lock()
|
|
||||||
*csv = append(*csv, []string{currentIP.String(), strconv.Itoa(pingRecv), strconv.FormatFloat(pingTimeAvg, 'f', 4, 64)})
|
|
||||||
mutex.Unlock()
|
|
||||||
}
|
|
||||||
<-control
|
|
||||||
}
|
|
||||||
166
utils/csv.go
Normal file
166
utils/csv.go
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/csv"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultOutput = "result.csv"
|
||||||
|
maxDelay = 9999 * time.Millisecond
|
||||||
|
minDelay = 0 * time.Millisecond
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
InputMaxDelay = maxDelay
|
||||||
|
InputMinDelay = minDelay
|
||||||
|
Output = defaultOutput
|
||||||
|
PrintNum = 10
|
||||||
|
)
|
||||||
|
|
||||||
|
// 是否打印测试结果
|
||||||
|
func NoPrintResult() bool {
|
||||||
|
return PrintNum == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 是否输出到文件
|
||||||
|
func noOutput() bool {
|
||||||
|
return Output == "" || Output == " "
|
||||||
|
}
|
||||||
|
|
||||||
|
type PingData struct {
|
||||||
|
IP *net.IPAddr
|
||||||
|
Sended int
|
||||||
|
Received int
|
||||||
|
Delay time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudflareIPData struct {
|
||||||
|
*PingData
|
||||||
|
recvRate float32
|
||||||
|
DownloadSpeed float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cf *CloudflareIPData) getRecvRate() float32 {
|
||||||
|
if cf.recvRate == 0 {
|
||||||
|
pingLost := cf.Sended - cf.Received
|
||||||
|
cf.recvRate = float32(pingLost) / float32(cf.Sended)
|
||||||
|
}
|
||||||
|
return cf.recvRate
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cf *CloudflareIPData) toString() []string {
|
||||||
|
result := make([]string, 6)
|
||||||
|
result[0] = cf.IP.String()
|
||||||
|
result[1] = strconv.Itoa(cf.Sended)
|
||||||
|
result[2] = strconv.Itoa(cf.Received)
|
||||||
|
result[3] = strconv.FormatFloat(float64(cf.getRecvRate()), 'f', 2, 32)
|
||||||
|
result[4] = strconv.FormatFloat(cf.Delay.Seconds()*1000, 'f', 2, 32)
|
||||||
|
result[5] = strconv.FormatFloat(cf.DownloadSpeed/1024/1024, 'f', 2, 32)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExportCsv(data []CloudflareIPData) {
|
||||||
|
if noOutput() || len(data) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fp, err := os.Create(Output)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("创建文件[%s]失败:%v", Output, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer fp.Close()
|
||||||
|
w := csv.NewWriter(fp) //创建一个新的写入文件流
|
||||||
|
_ = w.Write([]string{"IP 地址", "已发送", "已接收", "丢包率", "平均延迟", "下载速度 (MB/s)"})
|
||||||
|
_ = w.WriteAll(convertToString(data))
|
||||||
|
w.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func convertToString(data []CloudflareIPData) [][]string {
|
||||||
|
result := make([][]string, 0)
|
||||||
|
for _, v := range data {
|
||||||
|
result = append(result, v.toString())
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
type PingDelaySet []CloudflareIPData
|
||||||
|
|
||||||
|
func (s PingDelaySet) FilterDelay() (data PingDelaySet) {
|
||||||
|
if InputMaxDelay > maxDelay || InputMinDelay < minDelay {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
for _, v := range s {
|
||||||
|
if v.Delay > InputMaxDelay { // 平均延迟上限
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if v.Delay < InputMinDelay { // 平均延迟下限
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
data = append(data, v) // 延迟满足条件时,添加到新数组中
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PingDelaySet) Len() int {
|
||||||
|
return len(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PingDelaySet) Less(i, j int) bool {
|
||||||
|
iRate, jRate := s[i].getRecvRate(), s[j].getRecvRate()
|
||||||
|
if iRate != jRate {
|
||||||
|
return iRate < jRate
|
||||||
|
}
|
||||||
|
return s[i].Delay < s[j].Delay
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s PingDelaySet) Swap(i, j int) {
|
||||||
|
s[i], s[j] = s[j], s[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下载速度排序
|
||||||
|
type DownloadSpeedSet []CloudflareIPData
|
||||||
|
|
||||||
|
func (s DownloadSpeedSet) Len() int {
|
||||||
|
return len(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s DownloadSpeedSet) Less(i, j int) bool {
|
||||||
|
return s[i].DownloadSpeed > s[j].DownloadSpeed
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s DownloadSpeedSet) Swap(i, j int) {
|
||||||
|
s[i], s[j] = s[j], s[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s DownloadSpeedSet) Print(ipv6 bool) {
|
||||||
|
if NoPrintResult() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(s) <= 0 { // IP数组长度(IP数量) 大于 0 时继续
|
||||||
|
fmt.Println("\n[信息] 完整测速结果 IP 数量为 0,跳过输出结果。")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dateString := convertToString(s) // 转为多维数组 [][]String
|
||||||
|
if len(dateString) < PrintNum { // 如果IP数组长度(IP数量) 小于 打印次数,则次数改为IP数量
|
||||||
|
PrintNum = len(dateString)
|
||||||
|
}
|
||||||
|
headFormat := "%-16s%-5s%-5s%-5s%-6s%-11s\n"
|
||||||
|
dataFormat := "%-18s%-8s%-8s%-8s%-10s%-15s\n"
|
||||||
|
if ipv6 { // IPv6 太长了,所以需要调整一下间隔
|
||||||
|
headFormat = "%-40s%-5s%-5s%-5s%-6s%-11s\n"
|
||||||
|
dataFormat = "%-42s%-8s%-8s%-8s%-10s%-15s\n"
|
||||||
|
}
|
||||||
|
fmt.Printf(headFormat, "IP 地址", "已发送", "已接收", "丢包率", "平均延迟", "下载速度 (MB/s)")
|
||||||
|
for i := 0; i < PrintNum; i++ {
|
||||||
|
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 文件,可使用记事本/表格软件查看。\n", Output)
|
||||||
|
}
|
||||||
|
}
|
||||||
19
utils/progress.go
Normal file
19
utils/progress.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "github.com/cheggaaa/pb/v3"
|
||||||
|
|
||||||
|
type Bar struct {
|
||||||
|
pb *pb.ProgressBar
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBar(count int) *Bar {
|
||||||
|
return &Bar{pb.Simple.Start(count)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bar) Grow(num int) {
|
||||||
|
b.pb.Add(num)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bar) Done() {
|
||||||
|
b.pb.Finish()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user