From 517d01d4a9f29b6f445a7841132995d07746c207 Mon Sep 17 00:00:00 2001 From: badafans <990508464@qq.com> Date: Tue, 8 Dec 2020 12:05:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=A6=BB=E7=BA=BF=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决workers.dev的晚高峰无法访问或者被污染的问题 --- README.md | 2 - linux/src/cf.sh | 50 +++++++++---- shell/cf.sh | 52 +++++++++----- "windows/CF\344\274\230\351\200\211IP.bat" | 72 ++++++++++--------- "windows/Colo\346\217\220\345\217\226.bat" | 70 ++++++++++++++++++ ...345\215\225IP\346\265\213\351\200\237.bat" | 12 ++-- 6 files changed, 186 insertions(+), 72 deletions(-) create mode 100644 "windows/Colo\346\217\220\345\217\226.bat" diff --git a/README.md b/README.md index 62246e2..455d3a9 100644 --- a/README.md +++ b/README.md @@ -111,5 +111,3 @@ curl https://proxy.freecdn.workers.dev/?url=https://raw.githubusercontent.com/ba 其中 fping 是基于 GitHub 开源项目 https://github.com/schweikert/fping 4.2发行版修改而来,所有脚本均为本人原创内容,转载请注明出处! 对于 Cloudflare Anycast 节点汇总,均为本人扫描 Cloudflare 公开节点汇总而来,Cloudflare IP Ranges 来自 https://www.cloudflare.com/zh-cn/ips/ - -由于 speed.cloudflare.com 官方托管的CF Workers服务器资源有限(晚高峰容易出现error 1102:Workers exceeded resource limits),现在已经更换为自建服务器,请尽快更新至最新版本以免影响测速结果 diff --git a/linux/src/cf.sh b/linux/src/cf.sh index 407dcf7..27bf66d 100644 --- a/linux/src/cf.sh +++ b/linux/src/cf.sh @@ -12,32 +12,29 @@ do declare -i n declare -i count rm -rf ip.txt temp log.txt temp.txt - curl --ipv4 https://service.freecdn.workers.dev -# -o data.txt - publicip=$(cat data.txt | grep publicip: | cut -f 2- -d':') - domain=$(cat data.txt | grep domain: | cut -f 2- -d':') - file=$(cat data.txt | grep file: | cut -f 2- -d':') - url=$(cat data.txt | grep url: | cut -f 2- -d':') - version=$(cat data.txt | grep version: | cut -f 2- -d':') - if [ "$version" != "20201108" ] + datafile="./data.txt" + if [[ ! -f "$datafile" ]] then - echo 发现新版本: $version - echo 更新地址: $url - echo 更新后才可以使用 - exit + echo 获取CF节点IP + curl --retry 3 https://update.freecdn.workers.dev -o data.txt -# fi + domain=$(cat data.txt | grep domain= | cut -f 2- -d'=') + file=$(cat data.txt | grep file= | cut -f 2- -d'=') + databaseold=$(cat data.txt | grep database= | cut -f 2- -d'=') n=0 count=$(($RANDOM%5)) - for i in `cat data.txt | sed '1,5d'` + for i in `cat data.txt | sed '1,7d'` do if [ $n -eq $count ] then - echo $i>>ip.txt + randomip=$(($RANDOM%256)) + echo 生成随机IP $i$randomip + echo $i$randomip>>ip.txt count+=4 else n+=1 fi done - rm -rf data.txt n=0 m=$(cat ip.txt | wc -l) count=m/30+1 @@ -276,6 +273,29 @@ done start_seconds=$(date --date="$starttime" +%s) end_seconds=$(date --date="$endtime" +%s) clear + curl --ipv4 --resolve update.freecdn.workers.dev:443:$anycast --retry 3 -s -X POST -d '"CF-IP":"'$anycast'","Speed":"'$max'"' 'https://update.freecdn.workers.dev' -o temp.txt + publicip=$(cat temp.txt | grep publicip= | cut -f 2- -d'=') + colo=$(cat temp.txt | grep colo= | cut -f 2- -d'=') + url=$(cat temp.txt | grep url= | cut -f 2- -d'=') + url=$(cat temp.txt | grep url= | cut -f 2- -d'=') + app=$(cat temp.txt | grep app= | cut -f 2- -d'=') + databasenew=$(cat temp.txt | grep database= | cut -f 2- -d'=') + if [ "$app" != "20201208" ] + then + echo 发现新版本程序: $app + echo 更新地址: $url + echo 更新后才可以使用 + exit + fi + if [ "$databasenew" != "$databaseold" ] + then + echo 发现新版本数据库: $databasenew + mv temp.txt data.txt + echo 数据库 $databasenew 已经自动更新完毕 + fi + rm -rf temp.txt echo 优选IP $anycast 满足 $bandwidth Mbps带宽需求 echo 峰值速度 $max kB/s - echo 出口IP $publicip 总计用时 $((end_seconds-start_seconds)) 秒 \ No newline at end of file + echo 公网IP $publicip + echo 数据中心 $colo + echo 总计用时 $((end_seconds-start_seconds)) 秒 \ No newline at end of file diff --git a/shell/cf.sh b/shell/cf.sh index 20b1306..0ae95d6 100644 --- a/shell/cf.sh +++ b/shell/cf.sh @@ -12,34 +12,31 @@ do declare -i n declare -i per declare -i count - rm -rf icmp temp log.txt data.txt anycast.txt + rm -rf icmp temp log.txt anycast.txt temp.txt mkdir icmp - curl --ipv4 https://service.freecdn.workers.dev -# -o data.txt - publicip=$(cat data.txt | grep publicip: | cut -f 2- -d':') - domain=$(cat data.txt | grep domain: | cut -f 2- -d':') - file=$(cat data.txt | grep file: | cut -f 2- -d':') - url=$(cat data.txt | grep url: | cut -f 2- -d':') - version=$(cat data.txt | grep version: | cut -f 2- -d':') - if [ "$version" != "20201108" ] + datafile="./data.txt" + if [[ ! -f "$datafile" ]] then - echo 发现新版本: $version - echo 更新地址: $url - echo 更新后才可以使用 - exit + echo 获取CF节点IP + curl --retry 3 https://update.freecdn.workers.dev -o data.txt -# fi + domain=$(cat data.txt | grep domain= | cut -f 2- -d'=') + file=$(cat data.txt | grep file= | cut -f 2- -d'=') + databaseold=$(cat data.txt | grep database= | cut -f 2- -d'=') n=0 count=$(($RANDOM%5)) - for i in `cat data.txt | sed '1,5d'` + for i in `cat data.txt | sed '1,7d'` do if [ $n -eq $count ] then - echo $i>>anycast.txt + randomip=$(($RANDOM%256)) + echo 生成随机IP $i$randomip + echo $i$randomip>>anycast.txt count+=4 else n+=1 fi done - rm -rf data.txt n=0 m=$(cat anycast.txt | wc -l) count=m/30+1 @@ -308,6 +305,29 @@ done start_seconds=$(date --date="$starttime" +%s) end_seconds=$(date --date="$endtime" +%s) clear + curl --ipv4 --resolve update.freecdn.workers.dev:443:$anycast --retry 3 -s -X POST -d '"CF-IP":"'$anycast'","Speed":"'$max'"' 'https://update.freecdn.workers.dev' -o temp.txt + publicip=$(cat temp.txt | grep publicip= | cut -f 2- -d'=') + colo=$(cat temp.txt | grep colo= | cut -f 2- -d'=') + url=$(cat temp.txt | grep url= | cut -f 2- -d'=') + url=$(cat temp.txt | grep url= | cut -f 2- -d'=') + app=$(cat temp.txt | grep app= | cut -f 2- -d'=') + databasenew=$(cat temp.txt | grep database= | cut -f 2- -d'=') + if [ "$app" != "20201208" ] + then + echo 发现新版本程序: $app + echo 更新地址: $url + echo 更新后才可以使用 + exit + fi + if [ "$databasenew" != "$databaseold" ] + then + echo 发现新版本数据库: $databasenew + mv temp.txt data.txt + echo 数据库 $databasenew 已经自动更新完毕 + fi + rm -rf temp.txt echo 优选IP $anycast 满足 $bandwidth Mbps带宽需求 echo 峰值速度 $max kB/s - echo 出口IP $publicip 总计用时 $((end_seconds-start_seconds)) 秒 \ No newline at end of file + echo 公网IP $publicip + echo 数据中心 $colo + echo 总计用时 $((end_seconds-start_seconds)) 秒 \ No newline at end of file diff --git "a/windows/CF\344\274\230\351\200\211IP.bat" "b/windows/CF\344\274\230\351\200\211IP.bat" index 1ba0b41..328bee2 100644 --- "a/windows/CF\344\274\230\351\200\211IP.bat" +++ "b/windows/CF\344\274\230\351\200\211IP.bat" @@ -11,38 +11,25 @@ if %time:~3,1% EQU 0 (set /a startM=%time:~4,1%) else (set /a startM=%time:~3,2% if %time:~6,1% EQU 0 (set /a startS=%time:~7,1%) else (set /a startS=%time:~6,2%) goto start :start -title ȡCFڵIP -del data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt +del ip.txt CR.txt CRLF.txt cut.txt speed.txt temp.txt RD /S /Q temp cls -curl --ipv4 https://service.freecdn.workers.dev -o data.txt -# -for /f "delims=" %%a in ('findstr /C:"publicip" data.txt') do ( -set publicip=%%a -set publicip=!publicip:publicip:=! -) -for /f "delims=" %%a in ('findstr /C:"domain" data.txt') do ( +if not exist "data.txt" title ȡCFڵIP&curl --retry 3 https://update.freecdn.workers.dev -o data.txt -# +for /f "tokens=2 delims==" %%a in ('findstr /C:"domain" data.txt') do ( set domain=%%a -set domain=!domain:domain:=! ) -for /f "delims=" %%a in ('findstr /C:"file" data.txt') do ( +for /f "tokens=2 delims==" %%a in ('findstr /C:"file" data.txt') do ( set file=%%a -set file=!file:file:=! ) -for /f "delims=" %%a in ('findstr /C:"url" data.txt') do ( -set url=%%a -set url=!url:url:=! -) -for /f "delims=" %%a in ('findstr /C:"version" data.txt') do ( -set version=%%a -set version=!version:version:=! -if !version! NEQ 20201108 (echo °汾: !version! & echo µַ: !url! & title ºſʹ & echo ˳ & pause>nul & exit) +for /f "tokens=2 delims==" %%a in ('findstr /C:"database" data.txt') do ( +set databaseold=%%a ) +title CFڵIP set /a i=%random%%%5 set /a n=0 -for /f "skip=5" %%a in (data.txt) do ( -if !n! EQU !i! (echo %%a>>ip.txt & set /a i+=4) else (set /a n+=1) +for /f "skip=7" %%a in (data.txt) do ( +if !n! EQU !i! (set /a randomip=!random!%%256&echo IP %%a!randomip!&echo %%a!randomip!>>ip.txt&set /a i+=4) else (set /a n+=1) ) -del data.txt for /f "tokens=2 delims=:" %%a in ('find /c /v "" ip.txt') do ( set /a count=%%a set /a count=count/30+1 @@ -91,13 +78,13 @@ dir /o:-s /b > ../ip.txt cd .. set /a n=0 for /f "delims=" %%a in (ip.txt) do ( -set /a n+=1 & if !n!==1 set "a=%%a") +set /a n+=1&if !n!==1 set "a=%%a") set /a n=0 for /f "delims=" %%a in (ip.txt) do ( -set /a n+=1 & if !n!==2 set "b=%%a") +set /a n+=1&if !n!==2 set "b=%%a") set /a n=0 for /f "delims=" %%a in (ip.txt) do ( -set /a n+=1 & if !n!==3 set "c=%%a") +set /a n+=1&if !n!==3 set "c=%%a") for /f "delims=" %%a in ('dir temp /b /a-d^| find /v /c "&#@"') do ( if %%a GEQ 3 ( chcp 936 @@ -146,7 +133,7 @@ set /a Max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( if %%a GEQ !Max! set /a Max=%%a ) -if !Max! GEQ !Speed! (cls & echo ѡIP !a! %Bandwidth% Mbps & echo ֵٶ !Max! kB/s & goto end) else (goto two) +if !Max! GEQ !Speed! (cls&set anycast=!a!&goto end) else (goto two) :two chcp 936 del CRLF.txt cut.txt speed.txt @@ -187,7 +174,7 @@ set /a Max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( if %%a GEQ !Max! set /a Max=%%a ) -if !Max! GEQ !Speed! (cls & echo ѡIP !a! %Bandwidth% Mbps & echo ֵٶ !Max! kB/s & goto end) else (goto three) +if !Max! GEQ !Speed! (cls&set anycast=!a!&goto end) else (goto three) :three chcp 936 del CRLF.txt cut.txt speed.txt @@ -228,7 +215,7 @@ set /a Max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( if %%a GEQ !Max! set /a Max=%%a ) -if !Max! GEQ !Speed! (cls & echo ѡIP !b! %Bandwidth% Mbps & echo ֵٶ !Max! kB/s & goto end) else (goto four) +if !Max! GEQ !Speed! (cls&set anycast=!b!&goto end) else (goto four) :four chcp 936 del CRLF.txt cut.txt speed.txt @@ -269,7 +256,7 @@ set /a Max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( if %%a GEQ !Max! set /a Max=%%a ) -if !Max! GEQ !Speed! (cls & echo ѡIP !b! %Bandwidth% Mbps & echo ֵٶ !Max! kB/s & goto end) else (goto five) +if !Max! GEQ !Speed! (cls&set anycast=!b!&goto end) else (goto five) :five chcp 936 del CRLF.txt cut.txt speed.txt @@ -310,7 +297,7 @@ set /a Max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( if %%a GEQ !Max! set /a Max=%%a ) -if !Max! GEQ !Speed! (cls & echo ѡIP !c! %Bandwidth% Mbps & echo ֵٶ !Max! kB/s & goto end) else (goto six) +if !Max! GEQ !Speed! (cls&set anycast=!c!&goto end) else (goto six) :six chcp 936 del CRLF.txt cut.txt speed.txt @@ -351,7 +338,7 @@ set /a Max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( if %%a GEQ !Max! set /a Max=%%a ) -if !Max! GEQ !Speed! (cls & echo ѡIP !c! %Bandwidth% Mbps & echo ֵٶ !Max! kB/s & goto end) else (goto start) +if !Max! GEQ !Speed! (cls&set anycast=!c!&goto end) else (goto start) :end set /a stopH=%time:~0,2% if %time:~3,1% EQU 0 (set /a stopM=%time:~4,1%) else (set /a stopM=%time:~3,2%) @@ -359,7 +346,28 @@ if %time:~6,1% EQU 0 (set /a stopS=%time:~7,1%) else (set /a stopS=%time:~6,2%) set /a starttime=%startH%*3600+%startM%*60+%startS% set /a stoptime=%stopH%*3600+%stopM%*60+%stopS% if %starttime% GTR %stoptime% (set /a alltime=86400-%starttime%+%stoptime%) else (set /a alltime=%stoptime%-%starttime%) -echo IP !publicip! ܼʱ %alltime% +curl --ipv4 --resolve update.freecdn.workers.dev:443:!anycast! --retry 3 -s -X POST -d """CF-IP"":""!anycast!"",""Speed"":""!Max!""" "https://update.freecdn.workers.dev" -o temp.txt +for /f "tokens=2 delims==" %%a in ('findstr /C:"publicip" temp.txt') do ( +set publicip=%%a +) +for /f "tokens=2 delims==" %%a in ('findstr /C:"colo" temp.txt') do ( +set colo=%%a +) +for /f "tokens=2 delims==" %%a in ('findstr /C:"url" temp.txt') do ( +set url=%%a +) +for /f "tokens=2 delims==" %%a in ('findstr /C:"app" temp.txt') do ( +set app=%%a +if !app! NEQ 20201208 (echo °汾: !app!&echo µַ: !url!&title ºſʹ&echo ˳&pause>nul&exit) +) +for /f "tokens=2 delims==" %%a in ('findstr /C:"database" temp.txt') do ( +set databasenew=%%a +if !databasenew! NEQ !databaseold! (echo °汾ݿ: !databasenew!&move /Y temp.txt data.txt>nul&echo ݿ !databasenew! ѾԶ) +) +echo ѡIP !anycast! %Bandwidth% Mbps&echo ֵٶ !Max! kB/s +echo IP !publicip! +echo !colo! +echo ܼʱ %alltime% del ip.txt CR.txt CRLF.txt cut.txt speed.txt temp.txt RD /S /Q temp echo ر diff --git "a/windows/Colo\346\217\220\345\217\226.bat" "b/windows/Colo\346\217\220\345\217\226.bat" new file mode 100644 index 0000000..0e3e8b0 --- /dev/null +++ "b/windows/Colo\346\217\220\345\217\226.bat" @@ -0,0 +1,70 @@ +chcp 936 +cls +@echo off +cd "%~dp0" +color A +RD /S /Q temp +mkdir temp +cls +setlocal enabledelayedexpansion +set /a task=20 +set /p task=õcurl(Ĭ!task!): +set /a startH=%time:~0,2% +if %time:~3,1% EQU 0 (set /a startM=%time:~4,1%) else (set /a startM=%time:~3,2%) +if %time:~6,1% EQU 0 (set /a startS=%time:~7,1%) else (set /a startS=%time:~6,2%) +set /a n=1 +set /a m=1 +for /f "skip=7" %%i in ('curl https://update.freecdn.workers.dev -#') do ( +set /a randomip=!random!%%256 +echo url = "http://%%i!randomip!/cdn-cgi/trace">>temp/!m!.conf +set /a n+=1 +if !n! GTR !task! (set /a n=1&start /b curl -s --config temp/!m!.conf --connect-timeout 5 --max-time 15>temp/!m!.txt&set /a m+=1) else (echo %%i!randomip!) +) +start /b curl -s --config temp/!m!.conf --connect-timeout 5 --max-time 15>temp/!m!.txt +echo. +echo ȴcurl̽ +:loop1 +choice /t 5 /d y /n >nul +for /f "delims=" %%i in ('tasklist ^| find /c /i "curl.exe"') do ( +if %%i EQU 0 (echo %time% ǰcurl%%i) else (echo %time% ǰcurl%%i&goto loop1) +) +cd temp +echo. +echo ȡcoloԵ... +set /a n=1 +:loop2 +if !n! EQU !m! (findstr "h= colo=" !n!.txt>>colo.txt&del !n!.txt !n!.conf) else (findstr "h= colo=" !n!.txt>>colo.txt&del !n!.txt !n!.conf&set /a n+=1&goto loop2) +for /f "delims=" %%i in (colo.txt) do ( +set str=cloudflare%%i +if "!str:cloudflareh=!" NEQ "!str!" (set ip=%%i) +if "!str:cloudflarecolo=!" NEQ "!str!" (set colo=%%i&echo !ip!,!colo!>>temp.txt) +) +echo. +echo ɾЧַԵ... +for /f "tokens=2,3 delims==" %%i in (temp.txt) do ( +set str=%%i +set str=!str:colo=! +echo !str!%%j>>temp.csv +) +echo. +echo colo.csvԵ... +echo Address,Colocation>../colo.csv +for /f "tokens=1,2,3,4 delims=." %%i in (temp.csv) do ( +echo %%i.%%j.%%k.,%%l>>colo.csv +) +for /f "tokens=1,3 delims=," %%i in (colo.csv) do ( +echo %%i,%%j>>../colo.csv +) +cd .. +RD /S /Q temp +set /a stopH=%time:~0,2% +if %time:~3,1% EQU 0 (set /a stopM=%time:~4,1%) else (set /a stopM=%time:~3,2%) +if %time:~6,1% EQU 0 (set /a stopS=%time:~7,1%) else (set /a stopS=%time:~6,2%) +set /a starttime=%startH%*3600+%startM%*60+%startS% +set /a stoptime=%stopH%*3600+%stopM%*60+%stopS% +if %starttime% GTR %stoptime% (set /a alltime=86400-%starttime%+%stoptime%) else (set /a alltime=%stoptime%-%starttime%) +echo. +echo colo.csvѾɣܼʱ %alltime% +echo. +echo ر +pause>nul \ No newline at end of file diff --git "a/windows/\345\215\225IP\346\265\213\351\200\237.bat" "b/windows/\345\215\225IP\346\265\213\351\200\237.bat" index 81fb46b..611bdee 100644 --- "a/windows/\345\215\225IP\346\265\213\351\200\237.bat" +++ "b/windows/\345\215\225IP\346\265\213\351\200\237.bat" @@ -4,17 +4,15 @@ cd %~dp0 color A setlocal enabledelayedexpansion cls -curl --ipv4 https://service.freecdn.workers.dev -o data.txt -# -for /f "delims=" %%a in ('findstr /C:"domain" data.txt') do ( +set /p a=ѡ IP : +curl --ipv4 --resolve update.freecdn.workers.dev:443:%a% https://update.freecdn.workers.dev -o temp.txt -# +for /f "tokens=2 delims==" %%a in ('findstr /C:"domain" temp.txt') do ( set domain=%%a -set domain=!domain:domain:=! ) -for /f "delims=" %%a in ('findstr /C:"file" data.txt') do ( +for /f "tokens=2 delims==" %%a in ('findstr /C:"file" temp.txt') do ( set file=%%a -set file=!file:file:=! ) -del data.txt -set /p a=ѡ IP : +del temp.txt title ڲ %a% curl --resolve !domain!:443:%a% https://!domain!/!file! -o nul pause