diff --git a/linux/src/cf.sh b/linux/src/cf.sh index 5cf5b74..871119b 100644 --- a/linux/src/cf.sh +++ b/linux/src/cf.sh @@ -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地址下载测速 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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)) 秒 \ No newline at end of file diff --git a/shell/cf-openwrt.sh b/shell/cf-openwrt.sh new file mode 100644 index 0000000..63d75be --- /dev/null +++ b/shell/cf-openwrt.sh @@ -0,0 +1,388 @@ +#!/bin/bash +# random cloudflare anycast ip +declare -i bandwidth +declare -i speed +read -p "请设置期望到 CloudFlare 服务器的带宽大小(单位 Mbps):" bandwidth +speed=bandwidth*128*1024 +starttime=`date +'%Y-%m-%d %H:%M:%S'` +while true +do + while true + do + declare -i n + declare -i per + declare -i count + rm -rf icmp temp data.txt meta.txt log.txt anycast.txt temp.txt + mkdir icmp + while true + do + if [ -f "resolve.txt" ] + then + 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 + 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>>anycast.txt + done + rm -rf meta.txt data.txt + n=0 + m=$(cat anycast.txt | wc -l) + count=m/30+1 + for i in `cat anycast.txt` + do + ping -c $count -i 1 -n -q $i > icmp/$n.log& + n=$[$n+1] + per=$n*100/$m + while true + do + p=$(ps -ef | grep ping | grep -v "grep" | wc -l) + if [ $p -ge 200 ] + then + echo 正在测试 ICMP 丢包率:进程数 $p,已完成 $per % + sleep 1 + else + echo 正在测试 ICMP 丢包率:进程数 $p,已完成 $per % + break + fi + done + done + rm -rf anycast.txt + while true + do + p=$(ps -ef | grep ping | grep -v "grep" | wc -l) + if [ $p -ne 0 ] + then + echo 等待 ICMP 进程结束:剩余进程数 $p + sleep 1 + else + echo ICMP 丢包率测试完成 + break + fi + done + cat icmp/*.log | grep 'statistics\|loss' | sed -n '{N;s/\n/\t/p}' | cut -f 1 -d'%' | awk '{print $NF,$2}' | sort -n | awk '{print $2}' | sed '31,$d' > ip.txt + rm -rf icmp + echo 选取30个丢包率最少的IP地址下载测速 + mkdir temp + for i in `cat ip.txt` + do + echo $i 启动测速 + curl --resolve $domain:443:$i https://$domain/$file -o temp/$i -s --connect-timeout 2 --max-time 10& + done + echo 等待测速进程结束,筛选出三个优选的IP + sleep 15 + echo 测速完成 + ls -S temp > ip.txt + rm -rf temp + n=$(wc -l ip.txt | awk '{print $1}') + if [ $n -ge 3 ]; then + first=$(sed -n '1p' ip.txt) + second=$(sed -n '2p' ip.txt) + third=$(sed -n '3p' ip.txt) + rm -rf ip.txt + echo 优选的IP地址为 $first - $second - $third + echo 第一次测试 $first + curl --resolve $domain:443:$first 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 + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep k | sed 's/k//g'` + do + declare -i k + k=$i + k=k*1024 + echo $k >> speed.txt + done + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep M | sed 's/M//g'` + do + i=$(echo | awk '{print '$i'*10 }') + declare -i M + M=$i + M=M*1024*1024/10 + echo $M >> speed.txt + done + declare -i max + declare -i max1 + max=0 + for i in `cat speed.txt` + do + max=$i + if [ $i -ge $max ]; then + max=$i + fi + done + rm -rf log.txt speed.txt + if [ $max -ge $speed ]; then + anycast=$first + 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 + cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep -v 'k\|M' >> speed.txt + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep k | sed 's/k//g'` + do + declare -i k + k=$i + k=k*1024 + echo $k >> speed.txt + done + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep M | sed 's/M//g'` + do + i=$(echo | awk '{print '$i'*10 }') + declare -i M + M=$i + M=M*1024*1024/10 + echo $M >> speed.txt + done + declare -i max + declare -i max2 + max=0 + for i in `cat speed.txt` + do + max=$i + if [ $i -ge $max ]; then + max=$i + fi + done + rm -rf log.txt speed.txt + if [ $max -ge $speed ]; then + anycast=$first + 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 + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep k | sed 's/k//g'` + do + declare -i k + k=$i + k=k*1024 + echo $k >> speed.txt + done + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep M | sed 's/M//g'` + do + i=$(echo | awk '{print '$i'*10 }') + declare -i M + M=$i + M=M*1024*1024/10 + echo $M >> speed.txt + done + declare -i max + declare -i max1 + max=0 + for i in `cat speed.txt` + do + max=$i + if [ $i -ge $max ]; then + max=$i + fi + done + rm -rf log.txt speed.txt + if [ $max -ge $speed ]; then + anycast=$second + 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 + cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep -v 'k\|M' >> speed.txt + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep k | sed 's/k//g'` + do + declare -i k + k=$i + k=k*1024 + echo $k >> speed.txt + done + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep M | sed 's/M//g'` + do + i=$(echo | awk '{print '$i'*10 }') + declare -i M + M=$i + M=M*1024*1024/10 + echo $M >> speed.txt + done + declare -i max + declare -i max2 + max=0 + for i in `cat speed.txt` + do + max=$i + if [ $i -ge $max ]; then + max=$i + fi + done + rm -rf log.txt speed.txt + if [ $max -ge $speed ]; then + anycast=$second + 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 + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep k | sed 's/k//g'` + do + declare -i k + k=$i + k=k*1024 + echo $k >> speed.txt + done + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep M | sed 's/M//g'` + do + i=$(echo | awk '{print '$i'*10 }') + declare -i M + M=$i + M=M*1024*1024/10 + echo $M >> speed.txt + done + declare -i max + declare -i max1 + max=0 + for i in `cat speed.txt` + do + max=$i + if [ $i -ge $max ]; then + max=$i + fi + done + rm -rf log.txt speed.txt + if [ $max -ge $speed ]; then + anycast=$third + 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 + cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep -v 'k\|M' >> speed.txt + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep k | sed 's/k//g'` + do + declare -i k + k=$i + k=k*1024 + echo $k >> speed.txt + done + for i in `cat log.txt | tr '\r' '\n' | awk '{print $NF}' | sed '1,3d;$d' | grep M | sed 's/M//g'` + do + i=$(echo | awk '{print '$i'*10 }') + declare -i M + M=$i + M=M*1024*1024/10 + echo $M >> speed.txt + done + declare -i max + declare -i max2 + max=0 + for i in `cat speed.txt` + do + max=$i + if [ $i -ge $max ]; then + max=$i + fi + done + rm -rf log.txt speed.txt + if [ $max -ge $speed ]; then + anycast=$third + 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 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'=') + rm -rf temp.txt + echo $anycast>resolve.txt + echo 优选IP $anycast 满足 $bandwidth Mbps带宽需求 + 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)) 秒 \ No newline at end of file diff --git a/shell/cf.sh b/shell/cf.sh index 59edd5f..4186162 100644 --- a/shell/cf.sh +++ b/shell/cf.sh @@ -12,31 +12,66 @@ do declare -i n declare -i per declare -i count - rm -rf icmp temp log.txt anycast.txt temp.txt + rm -rf icmp temp data.txt meta.txt log.txt anycast.txt temp.txt mkdir icmp - 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'` + while true do - if [ $n -eq $count ] + if [ -f "resolve.txt" ] then - randomip=$(($RANDOM%256)) - echo 生成随机IP $i$randomip - echo $i$randomip>>anycast.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>>anycast.txt done + rm -rf meta.txt data.txt n=0 m=$(cat anycast.txt | wc -l) count=m/30+1 @@ -111,6 +146,7 @@ do echo $M >> speed.txt done declare -i max + declare -i max1 max=0 for i in `cat speed.txt` do @@ -125,6 +161,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 @@ -145,6 +182,7 @@ do echo $M >> speed.txt done declare -i max + declare -i max2 max=0 for i in `cat speed.txt` do @@ -159,7 +197,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 @@ -179,6 +224,7 @@ do echo $M >> speed.txt done declare -i max + declare -i max1 max=0 for i in `cat speed.txt` do @@ -193,6 +239,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 @@ -213,6 +260,7 @@ do echo $M >> speed.txt done declare -i max + declare -i max2 max=0 for i in `cat speed.txt` do @@ -227,7 +275,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 @@ -247,6 +302,7 @@ do echo $M >> speed.txt done declare -i max + declare -i max1 max=0 for i in `cat speed.txt` do @@ -261,6 +317,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 @@ -281,6 +338,7 @@ do echo $M >> speed.txt done declare -i max + declare -i max2 max=0 for i in `cat speed.txt` do @@ -295,39 +353,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)) 秒 \ 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 744be6d..5ca8917 100644 --- "a/windows/CF\344\274\230\351\200\211IP.bat" +++ "b/windows/CF\344\274\230\351\200\211IP.bat" @@ -4,38 +4,81 @@ cls cd "%~dp0" color A setlocal enabledelayedexpansion -set /p Bandwidth= CloudFlare ĴС(λ Mbps): -set /a Speed=%Bandwidth%*128 +set /p bandwidth= CloudFlare ĴС(λ Mbps): +set /a speed=%bandwidth%*128 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%) goto start :start -del ip.txt CR.txt CRLF.txt cut.txt speed.txt temp.txt +del data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt meta.txt RD /S /Q temp cls -if not exist "data.txt" title ȡCFڵIP&curl --retry 3 https://update.udpfile.com -o data.txt -# +if exist "resolve.txt" goto resolve +if not exist "resolve.txt" goto dnsresolve +:dnsresolve +title DNSȡCFڵIP +curl --ipv4 --retry 3 -v https://speed.cloudflare.com/__down>meta.txt 2>&1 +for /f "tokens=3 delims= " %%i in ('findstr "cf-meta-asn:" meta.txt') do ( +set asn=%%i +) +for /f "tokens=3 delims= " %%i in ('findstr "cf-meta-city:" meta.txt') do ( +set city=%%i +) +for /f "tokens=3 delims= " %%i in ('findstr "cf-meta-latitude:" meta.txt') do ( +set latitude=%%i +) +for /f "tokens=3 delims= " %%i in ('findstr "cf-meta-longitude:" meta.txt') do ( +set longitude=%%i +) +curl --ipv4 --retry 3 https://service.udpfile.com?asn=%asn%^&city=%city% -o data.txt -# +goto getip +:resolve +for /f "delims=" %%i in (resolve.txt) do ( +set resolveip=%%i +) +title ָȡCFڵIP +curl --ipv4 --resolve speed.cloudflare.com:443:%resolveip% --retry 3 -v https://speed.cloudflare.com/__down>meta.txt 2>&1 +for /f "tokens=3 delims= " %%i in ('findstr "cf-meta-asn:" meta.txt') do ( +set asn=%%i +) +for /f "tokens=3 delims= " %%i in ('findstr "cf-meta-city:" meta.txt') do ( +set city=%%i +) +for /f "tokens=3 delims= " %%i in ('findstr "cf-meta-latitude:" meta.txt') do ( +set latitude=%%i +) +for /f "tokens=3 delims= " %%i in ('findstr "cf-meta-longitude:" meta.txt') do ( +set longitude=%%i +) +curl --ipv4 --resolve service.udpfile.com:443:%resolveip% --retry 3 https://service.udpfile.com?asn=%asn%^&city=%city% -o data.txt -# +if not exist "data.txt" goto start +if not exist "meta.txt" goto start +del meta.txt +:getip +for /f "skip=4" %%i in (data.txt) do ( +echo %%i>>ip.txt +) for /f "tokens=2 delims==" %%a in ('findstr /C:"domain" data.txt') do ( set domain=%%a ) for /f "tokens=2 delims==" %%a in ('findstr /C:"file" data.txt') do ( set file=%%a ) -for /f "tokens=2 delims==" %%a in ('findstr /C:"database" data.txt') do ( -set databaseold=%%a +for /f "tokens=2 delims==" %%a in ('findstr /C:"url" data.txt') do ( +set url=%%a ) -title CFڵIP -set /a i=%random%%%5 -set /a n=0 -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) +for /f "tokens=2 delims==" %%a in ('findstr /C:"app" data.txt') do ( +set app=%%a +if !app! NEQ 20210306 (echo °汾: !app!&echo µַ: !url!&title ºſʹ&echo ˳&pause>nul&exit) ) +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 ) title ICMP -fping -f ip.txt -c %count% --interval=1 -s > ping.csv +fping -f ip.txt -c %count% --interval=0 -s > ping.csv findstr "%%" ping.csv > temp.csv del ping.csv del ip.txt @@ -129,16 +172,17 @@ set /a x=!y%!*1024/10 set /a z=x+y echo !z! >> speed.txt ) -set /a Max=0 +set /a max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( -if %%a GEQ !Max! set /a Max=%%a +if %%a GEQ !max! set /a max=%%a ) -if !Max! GEQ !Speed! (cls&set anycast=!a!&goto end) else (goto two) +set /a max1=max +if !max! GEQ !speed! (cls&set anycast=!a!&goto end) else (goto two) :two chcp 936 del CRLF.txt cut.txt speed.txt cls -echo һβ !a! ,ֵٶ !Max! kB/s +echo һβ !a! ,ֵٶ !max! kB/s echo ڶβ !a! curl --resolve !domain!:443:!a! https://!domain!/!file! -o nul --connect-timeout 5 --max-time 10 > CR.txt 2>&1 findstr "0:" CR.txt >> CRLF.txt @@ -170,16 +214,18 @@ set /a y=!y%!*1024/10 set /a z=x+y echo !z! >> speed.txt ) -set /a Max=0 +set /a max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( -if %%a GEQ !Max! set /a Max=%%a +if %%a GEQ !max! set /a max=%%a ) -if !Max! GEQ !Speed! (cls&set anycast=!a!&goto end) else (goto three) +set /a max2=max +if !max! GEQ !speed! (cls&set anycast=!a!&goto end) else (goto three) :three chcp 936 del CRLF.txt cut.txt speed.txt cls -echo ڶβ !a! ,ֵٶ !Max! kB/s +if !max1! GEQ !max2! (curl --ipv4 --resolve service.udpfile.com:443:!a! --retry 3 -s -X POST -d "20210306-!a!-!max1!" https://service.udpfile.com?asn=%asn%^&city=%city% -o nul --connect-timeout 5 --max-time 10) else (curl --ipv4 --resolve service.udpfile.com:443:!a! --retry 3 -s -X POST -d "20210306-!a!-!max2!" https://service.udpfile.com?asn=%asn%^&city=%city% -o nul --connect-timeout 5 --max-time 10) +echo ڶβ !a! ,ֵٶ !max! kB/s echo һβ !b! curl --resolve !domain!:443:!b! https://!domain!/!file! -o nul --connect-timeout 5 --max-time 10 > CR.txt 2>&1 findstr "0:" CR.txt >> CRLF.txt @@ -211,16 +257,17 @@ set /a y=!y%!*1024/10 set /a z=x+y echo !z! >> speed.txt ) -set /a Max=0 +set /a max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( -if %%a GEQ !Max! set /a Max=%%a +if %%a GEQ !max! set /a max=%%a ) -if !Max! GEQ !Speed! (cls&set anycast=!b!&goto end) else (goto four) +set /a max1=max +if !max! GEQ !speed! (cls&set anycast=!b!&goto end) else (goto four) :four chcp 936 del CRLF.txt cut.txt speed.txt cls -echo һβ !b! ,ֵٶ !Max! kB/s +echo һβ !b! ,ֵٶ !max! kB/s echo ڶβ !b! curl --resolve !domain!:443:!b! https://!domain!/!file! -o nul --connect-timeout 5 --max-time 10 > CR.txt 2>&1 findstr "0:" CR.txt >> CRLF.txt @@ -252,16 +299,18 @@ set /a y=!y%!*1024/10 set /a z=x+y echo !z! >> speed.txt ) -set /a Max=0 +set /a max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( -if %%a GEQ !Max! set /a Max=%%a +if %%a GEQ !max! set /a max=%%a ) -if !Max! GEQ !Speed! (cls&set anycast=!b!&goto end) else (goto five) +set /a max2=max +if !max! GEQ !speed! (cls&set anycast=!b!&goto end) else (goto five) :five chcp 936 del CRLF.txt cut.txt speed.txt cls -echo ڶβ !b! ,ֵٶ !Max! kB/s +if !max1! GEQ !max2! (curl --ipv4 --resolve service.udpfile.com:443:!b! --retry 3 -s -X POST -d "20210306-!b!-!max1!" https://service.udpfile.com?asn=%asn%^&city=%city% -o nul --connect-timeout 5 --max-time 10) else (curl --ipv4 --resolve service.udpfile.com:443:!b! --retry 3 -s -X POST -d "20210306-!b!-!max2!" https://service.udpfile.com?asn=%asn%^&city=%city% -o nul --connect-timeout 5 --max-time 10) +echo ڶβ !b! ,ֵٶ !max! kB/s echo һβ !c! curl --resolve !domain!:443:!c! https://!domain!/!file! -o nul --connect-timeout 5 --max-time 10 > CR.txt 2>&1 findstr "0:" CR.txt >> CRLF.txt @@ -293,16 +342,17 @@ set /a y=!y%!*1024/10 set /a z=x+y echo !z! >> speed.txt ) -set /a Max=0 +set /a max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( -if %%a GEQ !Max! set /a Max=%%a +if %%a GEQ !max! set /a max=%%a ) -if !Max! GEQ !Speed! (cls&set anycast=!c!&goto end) else (goto six) +set /a max1=max +if !max! GEQ !speed! (cls&set anycast=!c!&goto end) else (goto six) :six chcp 936 del CRLF.txt cut.txt speed.txt cls -echo һβ !c! ,ֵٶ !Max! kB/s +echo һβ !c! ,ֵٶ !max! kB/s echo ڶβ !c! curl --resolve !domain!:443:!c! https://!domain!/!file! -o nul --connect-timeout 5 --max-time 10 > CR.txt 2>&1 findstr "0:" CR.txt >> CRLF.txt @@ -334,41 +384,47 @@ set /a y=!y%!*1024/10 set /a z=x+y echo !z! >> speed.txt ) -set /a Max=0 +set /a max=0 for /f "tokens=1,2" %%a in ('type "speed.txt"') do ( -if %%a GEQ !Max! set /a Max=%%a +if %%a GEQ !max! set /a max=%%a ) -if !Max! GEQ !Speed! (cls&set anycast=!c!&goto end) else (goto start) +set /a max2=max +if !max! GEQ !speed! (cls&set anycast=!c!&goto end) else (goto seven) +:seven +chcp 936 +del CRLF.txt cut.txt speed.txt +cls +echo ڶβ !c! ,ֵٶ !max! kB/s +if !max1! GEQ !max2! (curl --ipv4 --resolve service.udpfile.com:443:!c! --retry 3 -s -X POST -d "20210306-!c!-!max1!" https://service.udpfile.com?asn=%asn%^&city=%city% -o nul --connect-timeout 5 --max-time 10) else (curl --ipv4 --resolve service.udpfile.com:443:!c! --retry 3 -s -X POST -d "20210306-!c!-!max2!" https://service.udpfile.com?asn=%asn%^&city=%city% -o nul --connect-timeout 5 --max-time 10) +goto start :end +set /a realbandwidth=max/128 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%) -curl --ipv4 --resolve update.udpfile.com:443:!anycast! --retry 3 -s -X POST -d "!anycast!-!Max!" "https://update.udpfile.com" -o temp.txt -for /f "tokens=2 delims==" %%a in ('findstr /C:"publicip" temp.txt') do ( +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 data.txt +for /f "tokens=2 delims==" %%a in ('findstr /C:"publicip" data.txt') do ( set publicip=%%a ) -for /f "tokens=2 delims==" %%a in ('findstr /C:"colo" temp.txt') do ( +for /f "tokens=2 delims==" %%a in ('findstr /C:"colo" data.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 20210226 (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 ѡIP !anycast! %bandwidth% Mbps +echo IP !publicip! +echo AS%asn% +echo γ %longitude%,%latitude% +echo META %city% +echo ʵ %realbandwidth% Mbps +echo ֵٶ !max! kB/s echo !colo! echo ܼʱ %alltime% -del ip.txt CR.txt CRLF.txt cut.txt speed.txt temp.txt +echo !anycast!>resolve.txt +echo !anycast!|clip +del data.txt ip.txt CR.txt CRLF.txt cut.txt speed.txt meta.txt RD /S /Q temp +echo ѡIPѾԶƵ echo ر pause>nul \ No newline at end of file