Skip to content

Commit eadae42

Browse files
committed
修复了一些已知的问题
1 parent fe27c23 commit eadae42

File tree

4 files changed

+347
-421
lines changed

4 files changed

+347
-421
lines changed

batch/CF优选IP-ANSI.bat

+81-97
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
1-
chcp 936>nul
1+
chcp 936 > nul
22
@echo off
33
cd "%~dp0"
4-
color A
54
setlocal enabledelayedexpansion
6-
set version=20220525
5+
set version=20220615
76

8-
:main
97
cls
8+
:main
109
title CF优选IP
11-
echo 1. IPV4优选&echo 2. IPV6优选&echo 3. 自定义IPV4段&echo 4. 单IP测速&echo 5. 清空缓存&echo 0. 退出&echo.
12-
set /p menu=请选择菜单:
10+
set /a menu=1
11+
echo 1. IPV4优选&echo 2. IPV6优选&echo 3. 单IP测速&echo 4. 清空缓存&echo 0. 退出&echo.
12+
set /p menu=请选择菜单(默认%menu%):
1313
if %menu%==0 exit
14-
if %menu%==1 title IPV4优选&set ips=ipv4&set /a selfmode=0&goto bettercloudflareip
15-
if %menu%==2 title IPV6优选&set ips=ipv6&set /a selfmode=0&goto bettercloudflareip
16-
if %menu%==3 title 自定义IPV4段&set ips=ipv4&set /a selfmode=1&set /p selfip=请输入C类自定义IPV4(格式 104.16.16):&goto bettercloudflareip
17-
if %menu%==4 title 单IP测速&call :singletest
18-
if %menu%==5 del ipv4.txt ipv6.txt data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt meta.txt>nul 2>&1&RD /S /Q rtt>nul 2>&1
14+
if %menu%==1 title IPV4优选&set ips=ipv4&goto bettercloudflareip
15+
if %menu%==2 title IPV6优选&set ips=ipv6&goto bettercloudflareip
16+
if %menu%==3 title 单IP测速&call :singletest&goto main
17+
if %menu%==4 del ipv4.txt ipv6.txt rtt.txt data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt meta.txt > nul 2>&1&RD /S /Q rtt > nul 2>&1&cls&echo 缓存已经清空&goto main
18+
cls
1919
goto main
2020

2121
:singletest
22+
set /a port=443
2223
set /p ip=请输入需要测速的IP:
23-
curl --resolve service.baipiaocf.ml:443:!ip! https://service.baipiaocf.ml -o temp.txt -#
24-
for /f "tokens=2 delims==" %%i in ('findstr "domain=" temp.txt') do (
25-
set domain=%%i
26-
)
27-
for /f "delims=" %%i in ('findstr "file=" temp.txt') do (
28-
set file=%%i
29-
set file=!file:~5!
24+
set /p port=请输入需要测速的端口(默认%port%):
25+
echo 正在测速 !ip! 端口 !port!
26+
goto download
27+
:download
28+
for /f "tokens=1,2 delims=_" %%i in ('curl --resolve speed.cloudflare.com:!port!:!ip! "https://speed.cloudflare.com:!port!/__down?bytes=300000000" -o nul --connect-timeout 5 --max-time 15 -w %%{http_code}_%%{speed_download}') do (
29+
set /a status=%%i
30+
set /a speed_download=%%j
31+
if !status! EQU 503 (cls&echo Cloudflare Workers 超出资源限制&echo 正在重新请求 Workers 资源&echo 正在测速 !ip! 端口 !port!&goto download) else (set /a speed_download=speed_download/1024&cls&echo !ip! 平均速度 !speed_download! kB/s)
3032
)
31-
del temp.txt
32-
title 正在测速 !ip!
33-
curl --resolve !domain!:443:!ip! https://!domain!/!file! -o nul --connect-timeout 5 --max-time 15
3433
goto :eof
3534

3635
:bettercloudflareip
37-
set /a tasknum=25
36+
set /a tasknum=10
3837
set /a bandwidth=1
3938
set /p bandwidth=请设置期望的带宽大小(默认最小%bandwidth%,单位 Mbps):
4039
set /p tasknum=请设置RTT测试进程数(默认%tasknum%,最大50):
4140
if %bandwidth% EQU 0 (set /a bandwidth=1)
42-
if %tasknum% EQU 0 (set /a tasknum=25&echo 进程数不能为0,自动设置为默认值)
41+
if %tasknum% EQU 0 (set /a tasknum=10&echo 进程数不能为0,自动设置为默认值)
4342
if %tasknum% GTR 50 (set /a tasknum=50&echo 超过最大进程限制,自动设置为最大值)
4443
set /a speed=bandwidth*128
4544
set /a startH=%time:~0,2%
@@ -49,15 +48,15 @@ call :start
4948
exit
5049

5150
:start
52-
del data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt meta.txt>nul 2>&1
53-
RD /S /Q rtt>nul 2>&1
51+
del rtt.txt data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt meta.txt > nul 2>&1
52+
RD /S /Q rtt > nul 2>&1
5453
if exist "!ips!.txt" goto resolve
5554
if not exist "!ips!.txt" goto dnsresolve
5655

5756
:dnsresolve
5857
echo DNS解析获取CF !ips! 节点
5958
echo 如果域名被污染,请手动创建 !ips!.txt 做解析
60-
curl --!ips! --retry 3 -s https://service.baipiaocf.ml/meta -o meta.txt
59+
curl --!ips! --retry 1 -s https://service.baipiaocf.ml/meta -o meta.txt --connect-timeout 2 --max-time 3
6160
if not exist "meta.txt" goto start
6261
for /f "tokens=2 delims==" %%i in ('findstr "asn=" meta.txt') do (
6362
set asn=%%i
@@ -80,7 +79,7 @@ for /f "tokens=2 delims==" %%i in ('findstr "longitude=" meta.txt') do (
8079
for /f "tokens=2 delims==" %%i in ('findstr "latitude=" meta.txt') do (
8180
set latitude=%%i
8281
)
83-
curl --!ips! --retry 3 https://service.baipiaocf.ml -o data.txt -#
82+
curl --!ips! --retry 1 https://service.baipiaocf.ml -o data.txt -# --connect-timeout 2 --max-time 3
8483
if not exist "data.txt" goto start
8584
goto checkupdate
8685

@@ -90,7 +89,7 @@ set resolveip=%%i
9089
)
9190
echo 指向解析获取CF !ips! 节点
9291
echo 如果长时间无法获取CF !ips! 节点,重新运行程序并选择清空缓存
93-
curl --!ips! --resolve service.baipiaocf.ml:443:!resolveip! --retry 3 -s https://service.baipiaocf.ml/meta -o meta.txt
92+
curl --!ips! --resolve service.baipiaocf.ml:443:!resolveip! --retry 1 -s https://service.baipiaocf.ml/meta -o meta.txt --connect-timeout 2 --max-time 3
9493
if not exist "meta.txt" goto start
9594
for /f "tokens=2 delims==" %%i in ('findstr "asn=" meta.txt') do (
9695
set asn=%%i
@@ -113,7 +112,7 @@ for /f "tokens=2 delims==" %%i in ('findstr "longitude=" meta.txt') do (
113112
for /f "tokens=2 delims==" %%i in ('findstr "latitude=" meta.txt') do (
114113
set latitude=%%i
115114
)
116-
curl --!ips! --resolve service.baipiaocf.ml:443:!resolveip! --retry 3 https://service.baipiaocf.ml -o data.txt -#
115+
curl --!ips! --resolve service.baipiaocf.ml:443:!resolveip! --retry 1 https://service.baipiaocf.ml -o data.txt -# --connect-timeout 2 --max-time 3
117116
if not exist "data.txt" goto start
118117
goto checkupdate
119118

@@ -130,100 +129,69 @@ set url=%%i
130129
)
131130
for /f "tokens=2 delims==" %%i in ('findstr "app=" data.txt') do (
132131
set app=%%i
133-
if !app! NEQ !version! (echo 发现新版本程序: !app!&echo 更新地址: !url!&title 更新后才可以使用&echo 按任意键退出程序&pause>nul&exit)
132+
if !app! NEQ !version! (echo 发现新版本程序: !app!&echo 更新地址: !url!&title 更新后才可以使用&echo 按任意键退出程序&pause > nul&exit)
134133
)
135-
if not exist "RTT.bat" echo 当前程序不完整&echo 请重新下载Release版本: !url! &pause>nul&exit
136-
if not exist "CR2CRLF.exe" echo 当前程序不完整&echo 请重新下载Release版本: !url! &pause>nul&exit
137-
if !selfmode!==0 (goto getip) else (set /a a=0&goto selfconfigip)
138-
139-
:getip
134+
if not exist "RTT.bat" echo 当前程序不完整&echo 请重新下载Release版本: !url! &pause > nul&exit
135+
if not exist "CR2CRLF.exe" echo 当前程序不完整&echo 请重新下载Release版本: !url! &pause > nul&exit
140136
for /f "skip=4" %%i in (data.txt) do (
141-
echo %%i>>ip.txt
137+
echo %%i >> ip.txt
142138
)
143139
goto rtt
144140

145-
:selfconfigip
146-
if !a!==256 (goto rtt) else (echo !selfip!.!a!>>ip.txt&set /a a=a+1&goto selfconfigip)
147-
148141
:rtt
149-
del meta.txt data.txt
142+
del rtt.txt meta.txt data.txt
150143
mkdir rtt
151144
for /f "tokens=2 delims=:" %%i in ('find /c /v "" ip.txt') do (
152145
set /a ipnum=%%i
153146
)
154-
if !tasknum! GTR !ipnum! set /a iplist=1
155-
set /a doubletasknum=tasknum*2
156-
if !ipnum! LSS !doubletasknum! (set /a iplist=2) else (set /a iplist=ipnum/tasknum)
157-
set /a a=1
158-
set /a b=1
147+
if !tasknum! EQU 0 set /a tasknum=1
148+
if !ipnum! LSS !tasknum! set /a tasknum=ipnum
149+
set /a n=1
159150
for /f "delims=" %%i in (ip.txt) do (
160-
echo %%i>>rtt/!b!.txt
161-
if !a! EQU !iplist! (set /a a=1&set /a b=b+1) else (set /a a=a+1)
151+
echo %%i >> rtt/!n!.txt
152+
if !n! EQU !tasknum! (set /a n=1) else (set /a n=n+1)
162153
)
154+
set /a n=1
163155
del ip.txt
164-
if !a! NEQ 1 set /a a=1&set /a b=b+1
165156
title RTT测试中
166157
goto rtttest
167158

168159
:rtttest
169-
if !a! NEQ !b! (start /b rtt.bat !a!>nul&set /a a=a+1&goto rtttest) else (goto rttstatus)
160+
start /b rtt.bat !n! > nul
161+
if !n! EQU !tasknum! (goto rttstatus) else (set /a n=n+1&goto rtttest)
170162

171163
:rttstatus
172-
timeout /T 2 /NOBREAK>nul
173164
for /f "delims=" %%i in ('dir rtt /o:-s /b^| findstr txt^| find /c /v ""') do (
174-
set /a taskstatus=%%i
175-
if !taskstatus! NEQ 0 (echo %time:~0,8% 等待RTT测试结束,剩余进程数 !taskstatus!&goto rttstatus) else (echo %time:~0,8% RTT测试完成)
176-
)
177-
for /f "delims=" %%i in ('dir rtt /o:-s /b^| find /c /v ""') do (
178165
set /a status=%%i
179-
if !status! EQU 0 echo 当前所有IP都存在RTT丢包&goto start
180-
)
181-
copy rtt\*.log rtt\ip.txt>nul
182-
sort rtt/ip.txt /O ip.txt
183-
for /f "tokens=2 delims=:" %%i in ('find /c /v "" ip.txt') do (
184-
if %%i LSS 5 (echo 当前所有IP都存在RTT丢包&goto start)
185-
)
186-
set /a a=0
187-
for /f "tokens=2,3 delims= " %%i in (ip.txt) do (
188-
set /a a=a+1
189-
if !a!==1 echo 第1个IP %%j 往返延迟 %%i 毫秒
190-
)
191-
set /a a=0
192-
for /f "tokens=2,3 delims= " %%i in (ip.txt) do (
193-
set /a a=a+1
194-
if !a!==2 echo 第2个IP %%j 往返延迟 %%i 毫秒
166+
if !status! NEQ 0 (echo %time:~0,8% 等待RTT测试结束,剩余进程数 !status!&timeout /T 1 /NOBREAK > nul&goto rttstatus) else (echo %time:~0,8% RTT测试完成)
195167
)
196-
set /a a=0
197-
for /f "tokens=2,3 delims= " %%i in (ip.txt) do (
198-
set /a a=a+1
199-
if !a!==3 echo 第3个IP %%j 往返延迟 %%i 毫秒
168+
for /f "delims=" %%i in ('dir rtt /o:-s /b^| findstr log^| find /c /v ""') do (
169+
set /a status=%%i
170+
if !status! NEQ 0 (
171+
copy rtt\*.log rtt.txt>nul
172+
) else (
173+
echo 当前所有IP都存在RTT丢包
174+
goto start
200175
)
201-
set /a a=0
202-
for /f "tokens=2,3 delims= " %%i in (ip.txt) do (
203-
set /a a=a+1
204-
if !a!==4 echo 第4个IP %%j 往返延迟 %%i 毫秒
205176
)
206-
set /a a=0
207-
for /f "tokens=2,3 delims= " %%i in (ip.txt) do (
208-
set /a a=a+1
209-
if !a!==5 echo 第5个IP %%j 往返延迟 %%i 毫秒
177+
echo 待测速的IP地址
178+
for /f "tokens=1,2 delims= " %%i in ('sort rtt.txt') do (
179+
echo %%j 往返延迟 %%i 毫秒
210180
)
211181
title 启动测速
212182
set /a a=0
213-
for /f "tokens=2,3 delims= " %%i in (ip.txt) do (
214-
set /a a=a+1
215-
if !a! GTR 5 echo 没有满足速度要求的IP&goto start
216-
del CRLF.txt cut.txt speed.txt>nul 2>&1
183+
for /f "tokens=1,2 delims= " %%i in ('sort rtt.txt') do (
184+
del CRLF.txt cut.txt speed.txt > nul 2>&1
217185
set avgms=%%i
218186
set anycast=%%j
219187
echo 正在测试 !anycast!
220-
curl --resolve !domain!:443:!anycast! https://!domain!/!file! -o nul --connect-timeout 5 --max-time 10 > CR.txt 2>&1
188+
curl --resolve !domain!:443:!anycast! https://!domain!/!file! -o nul --connect-timeout 1 --max-time 10 > CR.txt 2>&1
221189
findstr "0:" CR.txt >> CRLF.txt
222-
CR2CRLF CRLF.txt>nul
190+
CR2CRLF CRLF.txt > nul
223191
for /f "delims=" %%i in (CRLF.txt) do (
224192
set s=%%i
225193
set s=!s:~73,5!
226-
echo !s%!>>cut.txt
194+
echo !s%! >> cut.txt
227195
)
228196
for /f "delims=" %%i in ('findstr /v "k M" cut.txt') do (
229197
set x=%%i
@@ -252,24 +220,41 @@ for /f "tokens=1,2" %%i in ('type "speed.txt"') do (
252220
if %%i GEQ !max! set /a max=%%i
253221
)
254222
echo !anycast! 峰值速度 !max! kB/s
255-
if !max! GEQ !speed! cls&goto end
223+
if !max! GEQ !speed! goto end
256224
)
225+
goto start
257226

258227
:end
228+
echo !anycast!|clip
229+
echo !anycast! > !ips!.txt
230+
echo IP地址,往返延迟 > !ips!.csv
231+
for /f "tokens=1,2 delims= " %%i in ('sort rtt.txt') do (
232+
echo %%j,%%i ms >> !ips!.csv
233+
)
259234
set /a realbandwidth=max/128
260235
set /a stopH=%time:~0,2%
261236
if %time:~3,1% EQU 0 (set /a stopM=%time:~4,1%) else (set /a stopM=%time:~3,2%)
262237
if %time:~6,1% EQU 0 (set /a stopS=%time:~7,1%) else (set /a stopS=%time:~6,2%)
263238
set /a starttime=%startH%*3600+%startM%*60+%startS%
264239
set /a stoptime=%stopH%*3600+%stopM%*60+%stopS%
265240
if %starttime% GTR %stoptime% (set /a alltime=86400-%starttime%+%stoptime%) else (set /a alltime=%stoptime%-%starttime%)
266-
curl --!ips! --resolve service.baipiaocf.ml:443:!anycast! --retry 3 -s -X POST https://service.baipiaocf.ml -o data.txt
241+
echo 从服务器获取详细信息
242+
curl --!ips! --resolve service.baipiaocf.ml:443:!anycast! --retry 1 -s -X POST https://service.baipiaocf.ml -o data.txt --connect-timeout 2 --max-time 3
243+
cls
244+
if not exist "data.txt" (
245+
set publicip=获取超时
246+
set colo=获取超时
247+
) else (
267248
for /f "tokens=2 delims==" %%i in ('findstr "publicip=" data.txt') do (
268249
set publicip=%%i
269250
)
270251
for /f "tokens=2 delims==" %%i in ('findstr "colo=" data.txt') do (
271252
set colo=%%i
272253
)
254+
)
255+
del rtt.txt data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt meta.txt > nul 2>&1
256+
RD /S /Q rtt > nul 2>&1
257+
title 优选IP已经自动复制到剪贴板
273258
echo 优选IP !anycast!
274259
echo 公网IP !publicip!
275260
echo 自治域 AS!asn!
@@ -282,11 +267,10 @@ echo
282267
echo 往返延迟 !avgms! 毫秒
283268
echo 数据中心 !colo!
284269
echo 总计用时 !alltime!
285-
echo !anycast!>!ips!.txt
286-
echo !anycast!|clip
287-
del data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt meta.txt>nul 2>&1
288-
RD /S /Q rtt>nul 2>&1
289-
title 优选IP已经自动复制到剪贴板
270+
echo.
271+
echo 优选IP地址保存到 !ips!.txt
272+
echo 所有IP地址保存到 !ips!.csv
273+
echo.
290274
echo 按任意键关闭
291-
pause>nul
275+
pause > nul
292276
goto :eof

0 commit comments

Comments
 (0)