Skip to content

Commit

Permalink
增加指定ip文件的参数
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejun committed Apr 18, 2024
1 parent 3cc9e33 commit 013ad34
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 162 deletions.
97 changes: 0 additions & 97 deletions ipv6.txt

This file was deleted.

15 changes: 7 additions & 8 deletions script/openwrt/cf_ddns
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash
##版本:V2.1.1
#新功能,支持更新优选完毕后推送至TG,再也不怕脚本没有成功运行了。
#使用脚本需要安装jq和timeout,新增openwrt专用cf_RE.sh文件,运行cf_RE.sh即可在openwrt安装jq和timeout两个扩展。
#其他linux请自行安装jq和timeout。
#新功能,支持更新优选完毕后推送至TG,再也不怕脚本没有成功运行了。
#使用脚本需要安装jq和timeout,新增openwrt专用cf_RE.sh文件,运行cf_RE.sh即可在openwrt安装jq和timeout两个扩展。
#其他linux请自行安装jq和timeout。

ipv4Regex="((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])";
#默认关闭小云朵
Expand Down Expand Up @@ -82,12 +81,12 @@ fi;

if [ "$IP_ADDR" = "ipv6" ]; then
#开始优选IPv6
./CloudflareST $CFST_URL_R -t $CFST_T -n $CFST_N -dn $CFST_DN -tl $CFST_TL -tll $CFST_TLL -sl $CFST_SL -p $CFST_P -f ipv6.txt $USECC $CCODE_IS
echo "./CloudflareST $CFST_URL_R -t $CFST_T -n $CFST_N -dn $CFST_DN -tl $CFST_TL -tll $CFST_TLL -sl $CFST_SL -p $CFST_P -f ipv6.txt $CF_ADDR $USECC $CCODE_IS"
./CloudflareST $CFST_URL_R -t $CFST_T -n $CFST_N -dn $CFST_DN -tl $CFST_TL -tll $CFST_TLL -sl $CFST_SL -p $CFST_P -f $ipfile $USECC $CCODE_IS
echo "./CloudflareST $CFST_URL_R -t $CFST_T -n $CFST_N -dn $CFST_DN -tl $CFST_TL -tll $CFST_TLL -sl $CFST_SL -p $CFST_P -f $ipfile $CF_ADDR $USECC $CCODE_IS"
else
#开始优选IPv4
echo "./CloudflareST $CFST_URL_R -t $CFST_T -n $CFST_N -dn $CFST_DN -tl $CFST_TL -tll $CFST_TLL -sl $CFST_SL -p $CFST_P $CF_ADDR $USECC $CCODE_IS"
./CloudflareST $CFST_URL_R -t $CFST_T -n $CFST_N -dn $CFST_DN -tl $CFST_TL -tll $CFST_TLL -sl $CFST_SL -p $CFST_P $CF_ADDR $USECC $CCODE_IS
echo "./CloudflareST $CFST_URL_R -t $CFST_T -n $CFST_N -dn $CFST_DN -tl $CFST_TL -tll $CFST_TLL -sl $CFST_SL -p $CFST_P -f $ipfile $CF_ADDR $USECC $CCODE_IS"
./CloudflareST $CFST_URL_R -t $CFST_T -n $CFST_N -dn $CFST_DN -tl $CFST_TL -tll $CFST_TLL -sl $CFST_SL -p $CFST_P -f $ipfile $CF_ADDR $USECC $CCODE_IS
fi
echo "测速完毕";
if [ "$pause" = "false" ] ; then
Expand Down
2 changes: 1 addition & 1 deletion script/openwrt/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CFST_SL: 5
#是否按国家代码做分组筛选(是: true,否: false)
CCFLAG: true
#需要指定的国家代码,多个用逗号分隔(eg. US,JP)
CCODE: US,JP
CCODE:
#CF服务器对应端口
CF_ADDR: 443

Expand Down
124 changes: 68 additions & 56 deletions script/openwrt/start.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
#!/bin/bash

if [ $# -lt 1 ]; then
echo "start.sh config_file_path [ipfile]"
exit 0
fi

configfile=$1;
ipfile=$2;

echo "$configfile, $ipfile"

ipzipfile="txt.zip"

if [[ -e $ipzipfile ]]; then
rm -rf $ipzipfile;
rm -rf *.csv
fi;

echo "0.读取配置文件"
if [[ ! -e config.yaml ]]; then
echo "找不到config.yaml配置文件!"
if [[ ! -e $configfile ]]; then
echo "找不到$configfile配置文件!"
exit -1
fi

x_email=$(yq eval ".x_email" config.yaml)
hostname=$(yq eval ".hostname" config.yaml)
zone_id=$(yq eval ".zone_id" config.yaml)
api_key=$(yq eval ".api_key" config.yaml)
pause=$(yq eval ".pause" config.yaml)
clien=$(yq eval ".clien" config.yaml)
CFST_URL=$(yq eval ".CFST_URL" config.yaml)
CFST_N=$(yq eval ".CFST_N" config.yaml)
CFST_T=$(yq eval ".CFST_T" config.yaml)
CFST_DN=$(yq eval ".CFST_DN" config.yaml)
CFST_TL=$(yq eval ".CFST_TL" config.yaml)
CFST_TLL=$(yq eval ".CFST_TLL" config.yaml)
CFST_SL=$(yq eval ".CFST_SL" config.yaml)
CCFLAG=$(yq eval ".CCFLAG" config.yaml)
CCODE=$(yq eval ".CCODE" config.yaml)
CF_ADDR=$(yq eval ".CF_ADDR" config.yaml)
telegramBotToken=$(yq eval ".telegramBotToken" config.yaml)
telegramBotUserId=$(yq eval ".telegramBotUserId" config.yaml)
x_email=$(yq eval ".x_email" $configfile)
hostname=$(yq eval ".hostname" $configfile)
zone_id=$(yq eval ".zone_id" $configfile)
api_key=$(yq eval ".api_key" $configfile)
pause=$(yq eval ".pause" $configfile)
clien=$(yq eval ".clien" $configfile)
CFST_URL=$(yq eval ".CFST_URL" $configfile)
CFST_N=$(yq eval ".CFST_N" $configfile)
CFST_T=$(yq eval ".CFST_T" $configfile)
CFST_DN=$(yq eval ".CFST_DN" $configfile)
CFST_TL=$(yq eval ".CFST_TL" $configfile)
CFST_TLL=$(yq eval ".CFST_TLL" $configfile)
CFST_SL=$(yq eval ".CFST_SL" $configfile)
CCFLAG=$(yq eval ".CCFLAG" $configfile)
CCODE=$(yq eval ".CCODE" $configfile)
CF_ADDR=$(yq eval ".CF_ADDR" $configfile)
telegramBotToken=$(yq eval ".telegramBotToken" $configfile)
telegramBotUserId=$(yq eval ".telegramBotUserId" $configfile)

IFS=, read -r -a domains <<< "$hostname";
IFS=, read -r -a countryCodes <<< "$CCODE";
Expand All @@ -43,7 +54,7 @@ if [ ${#domains[@]} -eq 0 ]; then
fi

#检查域名和国家代码是否一一对应
if [ ! -z $CCFLAG ]; then
if [ "$CCFLAG" = "true" ]; then
echo "domain_num:$domain_num, countryCode_num:$countryCode_num"
if [ $domain_num -ne $countryCode_num ]; then
echo "The name and country code must correspond one to one!";
Expand Down Expand Up @@ -72,43 +83,44 @@ handle_err() {

trap handle_err ERR

echo "1.Download ip file."
for i in {1..3}
do
wget -O $ipzipfile https://zip.baipiao.eu.org

if [ $? != 0 ]; then
echo "get ip file failed, try again"
sleep 1
continue
else
echo "downloaded."
break
if [ -z $ipfile ]; then
echo "1.Download ip file."
for i in {1..3}
do
wget -O $ipzipfile https://zip.baipiao.eu.org

if [ $? != 0 ]; then
echo "get ip file failed, try again"
sleep 1
continue
else
echo "downloaded."
break
fi
done


if [ -e $ipzipfile ]; then
unzip -o $ipzipfile
fi


echo "2.Select the ip address of the desired port."
port=$( yq eval ".CF_ADDR" $configfile)
if [ -z $port ];then
port=443
fi;

for file in $(find . -type f -name "*-[0-1]-$port.txt"); do
echo "handling: $file"
cat "$file" >> tmp.txt
done

if [ -e tmp.txt ]; then
cat tmp.txt | sort -u > ip.txt
rm -rf tmp.txt
fi
done


if [ -e $ipzipfile ]; then
unzip -o $ipzipfile
fi


echo "2.Select the ip address of the desired port."
port=$( yq eval ".CF_ADDR" config.yaml)
if [ -z $port ];then
port=443
fi;

for file in $(find . -type f -name "*-[0-1]-$port.txt"); do
echo "handling: $file"
cat "$file" >> tmp.txt
done

if [ -e tmp.txt ]; then
cat tmp.txt | sort -u > ip.txt
rm -rf tmp.txt
fi


echo "Run scripts to test speed and update dns records."
source cf_ddns

0 comments on commit 013ad34

Please sign in to comment.