Skip to content

Commit

Permalink
支持离线数据库
Browse files Browse the repository at this point in the history
解决workers.dev的晚高峰无法访问或者被污染的问题
  • Loading branch information
badafans committed Dec 8, 2020
1 parent a3b955b commit 517d01d
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 72 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),现在已经更换为自建服务器,请尽快更新至最新版本以免影响测速结果
50 changes: 35 additions & 15 deletions linux/src/cf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
echo 公网IP $publicip
echo 数据中心 $colo
echo 总计用时 $((end_seconds-start_seconds))
52 changes: 36 additions & 16 deletions shell/cf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
echo 公网IP $publicip
echo 数据中心 $colo
echo 总计用时 $((end_seconds-start_seconds))
72 changes: 40 additions & 32 deletions windows/CF优选IP.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -351,15 +338,36 @@ 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%)
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 按任意键关闭
Expand Down
70 changes: 70 additions & 0 deletions windows/Colo提取.bat
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 517d01d

Please sign in to comment.