Sving1024 9 months ago
parent
commit
b15fe2c899
1 changed files with 15 additions and 4 deletions
  1. 15 4
      script/cfst_dnsmasq.sh

+ 15 - 4
script/cfst_dnsmasq.sh

@@ -3,16 +3,19 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
 export PATH
 # --------------------------------------------------------------
 #	项目: CloudflareSpeedTest 自动更新 dnsmasq 配置文件
-#	版本: 1.0.0
+#	版本: 1.0.1
 #	作者: XIU2,Sving1024
 #	项目: https://github.com/XIU2/CloudflareSpeedTest
 # --------------------------------------------------------------
 
 _UPDATE() {
 	echo -e "开始测速..."
-
+	BESTIP=""
+	BESTIP_IPV6="::"
 	# 这里可以自己添加、修改 CloudflareST 的运行参数
 	./CloudflareST -o "result_hosts.txt"
+	# 需要测速 IPv6 请取消注释
+	#./CloudflareST -o "result_hosts_ipv6.txt" -f ipv6.txt
 
 	# 如果需要 "找不到满足条件的 IP 就一直循环测速下去",那么可以将下面的两个 exit 0 改为 _UPDATE 即可
 	[[ ! -e "result_hosts.txt" ]] && echo "CloudflareST 测速结果 IP 数量为 0,跳过下面步骤..." && exit 0
@@ -23,18 +26,26 @@ _UPDATE() {
 	#[[ $(cat result_hosts.txt|wc -l) > 11 ]] && echo "CloudflareST 测速结果没有找到一个完全满足条件的 IP,重新测速..." && _UPDATE
 
 	BESTIP=$(sed -n "2,1p" result_hosts.txt | awk -F, '{print $1}')
+	# 需要测速 IPv6 请取消注释
+	#BESTIP_IPV6=$(sed -n "2,1p" result_hosts_ipv6.txt | awk -F, '{print $1}')
+
 	if [[ -z "${BESTIP}" ]]; then
 		echo "CloudflareST 测速结果 IP 数量为 0,跳过下面步骤..."
 		exit 0
 	fi
 	echo ${BESTIP} > nowip_hosts.txt
-	echo -e "最优 IP 为 ${BESTIP}\n"
+	echo -e "最优 IPv4 IP 为 ${BESTIP}\n"
+	# 需要测速 IPv6 请取消注释
+	#echo -e "最优 IPv6 IP 为 ${BESTIP_IPV6}\n"
 
     [[ -f cloudflare.conf ]] && rm cloudflare.conf
 
     cat site.conf | while read domain
     do
-        [[ ${domain:0:1} != "#" && ${domain} != "" ]] && echo "address=/${domain}/${BESTIP}" >> "cloudflare.conf"
+        if [[ ${domain:0:1} != "#" && ${domain} != "" ]]; then 
+			echo "address=/${domain}/${BESTIP}" >> "cloudflare.conf"
+			echo "address=/${domain}/${BESTIP_IPV6}" >> "cloudflare.conf"
+		fi
     done
 
     [[ -f /etc/dnsmasq.d/cloudflare.conf ]] && rm /etc/dnsmasq.d/cloudflare.conf