Skip to content

Commit

Permalink
精准数据库
Browse files Browse the repository at this point in the history
  • Loading branch information
badafans committed Mar 6, 2021
1 parent 2514b2f commit e0fdb0d
Show file tree
Hide file tree
Showing 4 changed files with 683 additions and 129 deletions.
133 changes: 94 additions & 39 deletions linux/src/cf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,69 @@ do
do
declare -i n
declare -i count
rm -rf ip.txt temp log.txt temp.txt
datafile="./data.txt"
if [[ ! -f "$datafile" ]]
then
echo 获取CF节点IP
curl --retry 3 https://update.udpfile.com -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,7d'`
rm -rf temp ip.txt data.txt meta.txt log.txt temp.txt
while true
do
if [ $n -eq $count ]
if [ -f "resolve.txt" ]
then
randomip=$(($RANDOM%256))
echo 生成随机IP $i$randomip
echo $i$randomip>>ip.txt
count+=4
echo 指向解析获取CF节点IP
resolveip=$(cat resolve.txt)
while true
do
if [ ! -f "meta.txt" ]
then
curl --ipv4 --resolve speed.cloudflare.com:443:$resolveip --retry 3 -v https://speed.cloudflare.com/__down>meta.txt 2>&1
else
asn=$(cat meta.txt | grep cf-meta-asn: | tr '\r' '\n' | awk '{print $3}')
city=$(cat meta.txt | grep cf-meta-city: | tr '\r' '\n' | awk '{print $3}')
latitude=$(cat meta.txt | grep cf-meta-latitude: | tr '\r' '\n' | awk '{print $3}')
longitude=$(cat meta.txt | grep cf-meta-longitude: | tr '\r' '\n' | awk '{print $3}')
curl --ipv4 --resolve service.udpfile.com:443:%resolveip% --retry 3 "https://service.udpfile.com?asn="$asn"&city="$city"" -o data.txt -#
break
fi
done
else
n+=1
echo DNS解析获取CF节点IP
while true
do
if [ ! -f "meta.txt" ]
then
curl --ipv4 --retry 3 -v https://speed.cloudflare.com/__down>meta.txt 2>&1
else
asn=$(cat meta.txt | grep cf-meta-asn: | tr '\r' '\n' | awk '{print $3}')
city=$(cat meta.txt | grep cf-meta-city: | tr '\r' '\n' | awk '{print $3}')
latitude=$(cat meta.txt | grep cf-meta-latitude: | tr '\r' '\n' | awk '{print $3}')
longitude=$(cat meta.txt | grep cf-meta-longitude: | tr '\r' '\n' | awk '{print $3}')
curl --ipv4 --retry 3 "https://service.udpfile.com?asn="$asn"&city="$city"" -o data.txt -#
break
fi
done
fi
if [ -f "data.txt" ]
then
break
fi
done
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'=')
app=$(cat data.txt | grep app= | cut -f 2- -d'=')
if [ "$app" != "20210306" ]
then
echo 发现新版本程序: $app
echo 更新地址: $url
echo 更新后才可以使用
exit
fi
for i in `cat data.txt | sed '1,4d'`
do
echo $i>>ip.txt
done
rm -rf meta.txt data.txt
n=0
m=$(cat ip.txt | wc -l)
count=m/30+1
./fping -f ip.txt -c $count -i 1 > fping.txt
./fping -f ip.txt -c $count -i 0 > fping.txt
sort -t/ -k 5n fping.txt | cut -f 1 -d: | sed '31,$d' > ip.txt
rm -rf fping.txt
echo 选取30个丢包率最少的IP地址下载测速
Expand Down Expand Up @@ -79,6 +114,7 @@ do
echo $M >> speed.txt
done
declare -i max
declare -i max1
max=0
for i in `cat speed.txt`
do
Expand All @@ -93,6 +129,7 @@ do
break
fi
max=$[$max/1024]
max1=max
echo 峰值速度 $max kB/s
echo 第二次测试 $first
curl --resolve $domain:443:$first https://$domain/$file -o /dev/null --connect-timeout 5 --max-time 10 > log.txt 2>&1
Expand All @@ -113,6 +150,7 @@ do
echo $M >> speed.txt
done
declare -i max
declare -i max2
max=0
for i in `cat speed.txt`
do
Expand All @@ -127,7 +165,14 @@ do
break
fi
max=$[$max/1024]
max2=max
echo 峰值速度 $max kB/s
if [ $max1 -ge $max2 ]
then
curl --ipv4 --resolve service.udpfile.com:443:$first --retry 3 -s -X POST -d ''20210306-$first-$max1'' "https://service.udpfile.com?asn="$asn"&city="$city"" -o /dev/null --connect-timeout 5 --max-time 10
else
curl --ipv4 --resolve service.udpfile.com:443:$first --retry 3 -s -X POST -d ''20210306-$first-$max2'' "https://service.udpfile.com?asn="$asn"&city="$city"" -o /dev/null --connect-timeout 5 --max-time 10
fi
echo 第一次测试 $second
curl --resolve $domain:443:$second https://$domain/$file -o /dev/null --connect-timeout 5 --max-time 10 > log.txt 2>&1
cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep -v 'k\|M' >> speed.txt
Expand All @@ -147,6 +192,7 @@ do
echo $M >> speed.txt
done
declare -i max
declare -i max1
max=0
for i in `cat speed.txt`
do
Expand All @@ -161,6 +207,7 @@ do
break
fi
max=$[$max/1024]
max1=max
echo 峰值速度 $max kB/s
echo 第二次测试 $second
curl --resolve $domain:443:$second https://$domain/$file -o /dev/null --connect-timeout 5 --max-time 10 > log.txt 2>&1
Expand All @@ -181,6 +228,7 @@ do
echo $M >> speed.txt
done
declare -i max
declare -i max2
max=0
for i in `cat speed.txt`
do
Expand All @@ -195,7 +243,14 @@ do
break
fi
max=$[$max/1024]
max2=max
echo 峰值速度 $max kB/s
if [ $max1 -ge $max2 ]
then
curl --ipv4 --resolve service.udpfile.com:443:$second --retry 3 -s -X POST -d ''20210306-$second-$max1'' "https://service.udpfile.com?asn="$asn"&city="$city"" -o /dev/null --connect-timeout 5 --max-time 10
else
curl --ipv4 --resolve service.udpfile.com:443:$second --retry 3 -s -X POST -d ''20210306-$second-$max2'' "https://service.udpfile.com?asn="$asn"&city="$city"" -o /dev/null --connect-timeout 5 --max-time 10
fi
echo 第一次测试 $third
curl --resolve $domain:443:$third https://$domain/$file -o /dev/null --connect-timeout 5 --max-time 10 > log.txt 2>&1
cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep -v 'k\|M' >> speed.txt
Expand All @@ -215,6 +270,7 @@ do
echo $M >> speed.txt
done
declare -i max
declare -i max1
max=0
for i in `cat speed.txt`
do
Expand All @@ -229,6 +285,7 @@ do
break
fi
max=$[$max/1024]
max1=max
echo 峰值速度 $max kB/s
echo 第二次测试 $third
curl --resolve $domain:443:$third https://$domain/$file -o /dev/null --connect-timeout 5 --max-time 10 > log.txt 2>&1
Expand All @@ -249,6 +306,7 @@ do
echo $M >> speed.txt
done
declare -i max
declare -i max2
max=0
for i in `cat speed.txt`
do
Expand All @@ -263,39 +321,36 @@ do
break
fi
max=$[$max/1024]
max2=max
echo 峰值速度 $max kB/s
if [ $max1 -ge $max2 ]
then
curl --ipv4 --resolve service.udpfile.com:443:$third --retry 3 -s -X POST -d ''20210306-$third-$max1'' "https://service.udpfile.com?asn="$asn"&city="$city"" -o /dev/null --connect-timeout 5 --max-time 10
else
curl --ipv4 --resolve service.udpfile.com:443:$third --retry 3 -s -X POST -d ''20210306-$third-$max2'' "https://service.udpfile.com?asn="$asn"&city="$city"" -o /dev/null --connect-timeout 5 --max-time 10
fi
fi
done
break
done
max=$[$max/1024]
declare -i realbandwidth
realbandwidth=max/128
endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s)
end_seconds=$(date --date="$endtime" +%s)
clear
curl --ipv4 --resolve update.udpfile.com:443:$anycast --retry 3 -s -X POST -d ''$anycast-$max'' 'https://update.udpfile.com' -o temp.txt
curl --ipv4 --resolve service.udpfile.com:443:$anycast --retry 3 -s -X POST -d ''20210306-$anycast-$max'' "https://service.udpfile.com?asn="$asn"&city="$city"" -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" != "20210226" ]
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 $anycast>resolve.txt
echo 优选IP $anycast 满足 $bandwidth Mbps带宽需求
echo 峰值速度 $max kB/s
echo 公网IP $publicip
echo 自治域 AS$asn
echo 经纬度 $longitude,$latitude
echo META城市 $city
echo 实测带宽 $realbandwidth Mbps
echo 峰值速度 $max kB/s
echo 数据中心 $colo
echo 总计用时 $((end_seconds-start_seconds))
Loading

0 comments on commit e0fdb0d

Please sign in to comment.